<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- v-for="item in items" -->
<template id = "row">
<span>{{ cc.msg }}</span> <span>note</span>
</template>
<ul id="example-1">
<item v-for="item in items" cc="item"></item>
</ul>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>
Vue.component('item', {
name : 'item',
template: '#row',
props: ['cc']
})
var example1 = new Vue({
el: '#example-1',
data: {
items: [
{message: 'Foo' },
{message: 'Bar' }
]
}
})
</script>
</body>
</html>
如上图所示,item组件中访问不到数据,也没有提示错误
动态属性要用指令绑定,改为
<item v-for="item in items" v-bind:cc="item"></item>
或者简写为
<item v-for="item in items" :cc="item"></item>