子组件定义data,并不能像根组件那样定义成对象,而是应该定义成函数,并把值进行返回
因为子组件会被调用很多次,并不希望子组件的数据和其他组件的数据产生冲突,所以通过函数返回对象让每个子组件都有独立的数据
<!DOCTYPE html>
<html>
<head>
<title>change color</title>
<script src="./vue.js"></script>
</head>
<body>
<div id='app'>
<table>
<tbody>
<tr is="row"></tr>
<tr is="row"></tr>
<tr is="row"></tr>
</tbody>
</table>
</div>
<script>
Vue.component('row',{
data(){
return {
content:'row',
index:'1'
}
},
template:'<tr><td>this is a {{content}},{{index}}</td></tr>'
})
var vm=new Vue({
el:'#app',
})
</script>
</body>
</html>