Vue x-template的使用與學習
阿新 • • 發佈:2018-12-15
<!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>x-template的使用學習</title>
</head>
<body>
<div id='app'>
<my-component></my-component>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<!-- 元件內容 id為 my-component type 為text/x-template -->
<script type='text/x-template' id='my-component'>
<div> 這是元件內容</div>
</script>
<script>
// 宣告一個元件 my-component 引入id 為my-component
Vue.component('my-component', {
template: '#my-component'
})
var app = new Vue({
el: '#app'
})
</script>
</html>