如果這樣寫就沒有效果,為什么?
<div id="root" v-on:click="handClick"></div>
<script>
new Vue({
el:"#root",
template:"<span>123 {{content}}</span>",
data:{
content:"helloa"
},
methods:{
handClick:function(){
this.content="world";
}
}
});
</script>
<div id="root" v-on:click="handClick"></div>
<script>
new Vue({
el:"#root",
template:"<span>123 {{content}}</span>",
data:{
content:"helloa"
},
methods:{
handClick:function(){
this.content="world";
}
}
});
</script>
2018-06-15
舉報
2018-06-15
v-on:click事件應該寫在模板中的span上
2018-12-27
因為你的template里面設置了內容。template:"<span>123 {{content}}</span>",
所以導致root被template里的內容替換,你再在root標簽里面寫指令或者任何東西,都不會顯示的,因為頁面不存在這個標簽了,自然事件沒有反應
兩種方法 第一種就是樓上說的 在模板上定義
第二種就是template:''定義成空,或者把template刪除。