<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<mycom></mycom>
</div>
<!--在被控制的#app的外面,使用template元素,定義組件的HTML模板結構-->
<template id="templ">
<div>
<h1>
這是通過template元素在外部定義組件的形式
</h1>
</div>
</template>
</body>
<script>
Vue.component('mycom',{
template: '#templ',
})
//創建一個vue實例
//當我們導入包之後,在瀏覽器的內存中就多了一個vue構造函數
var vm = new Vue({
el: '#app',//表示當前我們new的這個vue實例要控制頁面上的哪個區域
data: { //data屬性中存放的是el中要用到的數據
flag: false
}
});
</script>
</html>