vue组件模块抽离

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <comp>
      </comp>
    </div>

    <!-- 法一 -->
    <script type="text/x-text/x-handlebars-template" id="comp1">
      <div id="">
        <p>Hello Vue.js!</p>
        <p>Hello furong!</p>
      </div>
    </script>

    <!-- 法二 -->
    <template id="comp2">
      <div id="">
        <p>Hello Vue.js!</p>
        <p>Hello furong!</p>
      </div>
    </template>

    <script>
      const app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue.js!',
        },
        components: {
          comp: {
            template: '#comp1',
          },
        }
      })
    </script>
  </body>
</html>

posted @ 2021-07-05 18:49  thomas_blog  阅读(104)  评论(0编辑  收藏  举报