@ViewData["Title"]
赞
踩
@{ ViewData["Title"] = "parent";}<h1>@ViewData["Title"]</h1> <div id="app"> <cpn ref="cpnref"> </cpn></div> <template id="cpn"> <div> <h2>我是子組件</h2> <button v-on:click="subcmpclick">子組件按鈕</button> </div> </template> <script src="~/js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { message: 'test', }, components: { cpn: { template: '#cpn', data() { return { message: '子組件的數據信息傳遞' } }, methods: { subcmpclick() { console.log('$parent',this.$parent) console.log('$root',this.$root) } } } }, }) </script>