M
M
Max Zhukov2017-09-29 21:52:25
Vue.js
Max Zhukov, 2017-09-29 21:52:25

How to dynamically change component properties in vue outside of it?

Given the code that changes the props of the component dynamically, but here it changes them through the properties of el #app.

<div id="app">
        <input type="text" v-model="width">
        <br>
        <br>
        <input type="text" v-model="height">
        <br>
        <br>
        <br>
        <br>
        <br>
        <test :width="width" :height="height"></test>
    </div>
    <script>
    Vue.component('test', {
        template: '<div><input :value="width" type="text"><br><br><input :value="height" type="text"></div>',
        props: ['width', 'height']
    })
    new Vue({
        el: '#app',
        data: {
            width: 0,
            height: 0
        }
    });
    </script>

Is it possible to change component properties without properties in el #app? Like, for example, like this:
<div id="app">
        <input type="text" v-model="width(чтобы бралось с компонента как-нибудь)">
        <br>
        <br>
        <input type="text" v-model="height(чтобы бралось с компонента как-нибудь)">
        <br>
        <br>
        <br>
        <br>
        <br>
        <test></test>
    </div>
    <script>
    Vue.component('test', {
        template: '<div><input :value="width" type="text"><br><br><input :value="height" type="text"></div>',
            data: function(){
       return{
         width:0,
         height:0
         } 
       }
    })
    new Vue({
        el: '#app'
    });
    </script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-10-01
@MaksZhukov

In the test component, add a data section and write these properties in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question