你在組件中是不能利用到Vue中的數(shù)據(jù)的,你只能在你的組件里面定義一個(gè)data的返回函數(shù),不能是數(shù)據(jù)結(jié)構(gòu),不然會(huì)報(bào)錯(cuò)。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<div>
<aaa></aaa>
<aaa></aaa>
<aaa></aaa>
</div>
</div>
<template id="aaa">
<div>
<h2>{{ title }}</h2>
<p>我是內(nèi)容,呵呵呵</p>
</div>
</template>
<script src="../js/vue.js"></script>
<script>
Vue.component('aaa',{
template: '#aaa',
data() {
return {
title: 'abc'
}
}
})
const app = new Vue({
el: '#app',
data: {
}
})
</script>
</body>
</html>