<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件使用中的细节点,子组件的正确使用方式</title>
<script src='./vue.js'></script>
</head>
<body>
<div id="root">
<table>
<tbody>
<tr is="row"></tr>
<tr is="row"></tr>
<tr is="row"></tr>
</tbody>
</table>
</div>
<script>
Vue.component('row', {
data: {
contenet: 'this is a row'
},
template: '<tr><td>{{content}}</td> </tr>'
})
var vm = new Vue({
el: '#root'
})
</script>
</body>
</html>
运行中 页面报错
在vuezhong 如果在根组件中定义 data 不会出现如何问题 .
但是在子组件中 必须定义函数
正确代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件使用中的细节点2</title>
<script src='./vue.js'></script>
</head>
<body>
<div id="root">
<table>
<tbody>
<tr is="row"></tr>
<tr is="row"></tr>
<tr is="row"></tr>
</tbody>
</table>
</div>
<script>
Vue.component('row', {
data: function() {
return {
content: 'this is content'
}
},
template: '<tr><td>{{content}}</td> </tr>'
})
var vm = new Vue({
el: '#root',
})
</script>
</body>
</html>