老师,帮忙看一下代码哪里写错了
来源:2-7 使用 Composition API 开发TodoList(1)
weixin_慕姐4338681
2022-07-21 14:51:15
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>lesson21</title> <script src="../vue@3.2.23.js"></script> </head> <body> <div id="root"></div> </body> <script> const app = Vue.createApp({ setup() { const {ref,reactive} = Vue const inputValue = ref("123") const list = reactive([]) const handleInputValueChange = (e) => { inputValue.value = e.target.value } const addItemToList = () => { list.push(inputValue.value) } return {inputValue,list,handleInputValueChange,addItemToList} }, template: ` <div> <div> <input :value="inputValue @input="handleInputValueChange" /> <button @click="addItemToList">增加</button> </div> </div> <ul> <li v-for="(item,index) in list" :key="index">{{item}}</li> </ul> ` }) const vm = app.mount('#root'); </script> </html>
1回答
好帮手慕慕子
2022-07-21
同学你好, input标签绑定value属性是,属性值缺少结束的引号,导致解析异常,如下图所示:
建议添加引号后,再测试下,祝学习愉快~
相似问题