<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>组件模板抽离写法</title>
</head>
<body>
<div id="app">
<cpn></cpn>
</div>
<!--script标签实现模板分离-->
<!--<script type="text/x-template" id="cpn">-->
<!-- <div>-->
<!-- <h2>使用script分离模板</h2>-->
<!-- <hr>-->
<!-- </div>-->
<!--</script>-->
<!--使用template标签实现模板分离-->
<template id="cpn">
<div>
<h2>使用script分离模板</h2>
<hr>
</div>
</template>
<script src="js/vue.js"></script>
<script>
Vue.component('cpn', {
template: '#cpn'
})
const app = new Vue({
el: '#app',
})
</script>
</body>
</html>