search

Home  >  Q&A  >  body text

javascript - The value in the component cannot be dynamically bound.

This is the code of the component to be written, and the code that is not a component

    <p id="parent">
        <child :message="animal"></child>
    </p>

    <select name="sth" id="sth">
        <option :value="value">{{text}}</option>
    </select>

The bottom part is JS

Vue.component('child',{
    template:'<select :name="message+\'Select\'">\
        <optgroup :label="message">\
            <option :value="message">{{message}}</option>\
        </optgroup>\
    </select>',
    props:['message']
});
new Vue({
    el:"#parent",
    data:{
        animal:'phoenix'
    }
});
new Vue({
    el:"#sth",
    data:{
        value:'animal',
        text:'animation'
    }
});

The final rendering is

<p id="parent">
    <select name="phoenixSelect">
        <optgroup label="phoenix">
            <option>phoenix</option>
        </optgroup>
    </select>
</p>
<select name="sth" id="sth">
    <option value="animal">animation</option>
</select>

The non-component one below, the value can be displayed as a dynamic value animal normally, and the one above is a component, the name and label are normal, but the value cannot be displayed. Why?

曾经蜡笔没有小新曾经蜡笔没有小新2746 days ago380

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:20:31

    Yes https://jsfiddle.net/stardew/...

    reply
    0
  • Cancelreply