2016-12-17 36 views

回答

1

你可以直接綁定到數據,代碼如下:

var demo = new Vue({ 
 
    el: "#demo", 
 
    data: { 
 
     user: { 
 
     name: "please enter" 
 
     } 
 
    } 
 
})
<script src="https://unpkg.com/vue/dist/vue.min.js"></script> 
 
<div id="demo"> 
 
    <input v-model="user.name"> 
 
    <span>{{user.name}}</span> 
 
</div>

1

這也適用於Vue,請務必在數據中定義完整的對象,以使其成爲被動的,下面是工作fiddle

Vue公司代碼

var demo = new Vue({ 
    el: '#demo', 
    data: function(){ 
     return { 
     user: { 
      name: 'This is working fine' 
     } 
     }; 
    } 
})