vue组件的两种抽离方式

两种组件抽离方式,写法

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
    {{message}}
  <cpn></cpn>
</div>
<script type="text/x-template" id="cpn1">
<div>
  <h1>我是标题</h1>
  <p>我是内容,哈哈哈</p>
</div>
</script>
<script src="../vue.js"></script>
<template id="cpn2">
  <div>
    <h1>我是标题二</h1>
    <p>我是内容,呵呵呵呵</p>
  </div>
</template>
<script>
  Vue.component('cpn',{
    template:'#cpn2'
  })
  const app = new Vue({
    el: '#app',
    data: {
      message: 'hello'
    }
  })
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/ch2020/p/14841517.html