亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

怎么添加單擊事件就報錯啊?

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Todolist</title>

<script type="text/javascript"? src="./vue.js"></script>

</head>

<body>


<div id="root">

<div>

? <input v-model="inputValue"></input>

? <button @click="handlseSubmit">提交</button>

</div>

? ? ? ?<ul><todo-item

? ? v-for="(item,index) of list"? :key="index" :content="item"></todo-item></ul>



</div>


<script>


Vue.component("todo-item",{

props:["content"],/*全局組件*/

? ? template:"<li @click="handClick" >{{content}}</li>",? /*這里只要添加單擊事件就報錯啊 button那個單擊事件就沒問題*/

? ? methods:{

? ? ?handClick:function(){

? ? ?alert("asd")

? ? ?}

? ? }

});





// var TodoItme={

// ?template:"<li>局部組件</li>"

// }

new Vue({

? ? el:"#root",

? ? // components:{"todo-item":TodoItme},/*局部組件注冊*/

? ? data:{

? ? ?inputValue:"",

? ? ?list:[]

? ? ?},

? ? ?methods:{

? ? ?handlseSubmit:function(){

? ? ?this.list.push(this.inputValue)

? ? ?this.inputValue=""

? ? ?}

? ? ?}

});


</script>

</body>

</html>


正在回答

1 回答

因為template外面層嵌套的是雙引號,你里面的點擊內容也是雙引號,所以導致無法解析

解決方法:????雙引號嵌套,內容需用單引號擴住

????????????? ??? 單引號嵌套,內容需用雙引號擴住

4 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

怎么添加單擊事件就報錯啊?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號