在初学 vue ,代码也是抄来的,ide 用 vsc 和 codespaces 22 行( persons:[ )的冒号报错我实在看不懂 ide 提示 ';' expected.javascript any 但是;加哪里完全看不出来
<html>
<head>
<meta charset="utf-8">
<title>Vue 学习</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="app">
<input type="text" placeholder="输入" v-model="keyWord">
<ul>
<li v-for="(p,index) of filPersons" :key="index">
{{p.name}}-{{p.age}}-{{p.sex}}
</li>
</ul>
</div>
<script>
const app = {
data() {
keyWord:'',
persons:[
{id:'001',name:"马冬梅",age:19,sex:'女' },
{id:'002',name:"周冬雨",age:20,sex:'女' },
{id:'003',name:"周杰伦",age:21,sex:'男' },
{id:'004',name:"温兆伦",age:22,sex:'男' }
]
},
computed: {
filPersons(){
return this.persons.filter((p)=>{
return p.name.indexOf(this.keyWord) !== -1
})
}
}
}
Vue.createApp(app).mount('#app')
</script>
</body>
</html>
1
zcf0508 2023-04-19 19:19:05 +08:00 via Android
data 是一个函数,应该返回一个对象,你现在这不符合语法
|