美文网首页
使用script或template标签:分离js代码templa

使用script或template标签:分离js代码templa

作者: 前端召唤师 | 来源:发表于2019-07-16 11:26 被阅读0次

参考:https://www.jianshu.com/p/332252abe016

方法一. script:

<div id="app">
      <com-first></com-first>
 </div>
 <script type="text/x-template" id="comFirst">
      <div>component 1</div>
  </script>
<script> 
        Vue.component('com-first',{
            template: '#comFirst'
        })
        
        new Vue({
            el: '#app'
        })        
</script>

方法二. template:

<div id="app">
      <com-first></com-first>
</div>
<template id="comFirst">
      <div>component 1</div>
</template>
<script>
     Vue.component('com-first',{
            template: '#comFirst'
        })
        
        new Vue({
            el: '#app'
        })
</script>

相关文章

  • 使用script或template标签:分离js代码templa

    参考:https://www.jianshu.com/p/332252abe016 方法一. script: 方法...

  • js知识点总结(1)

    js的声明和引入: 1.在head标签中使用script标签声明js代码域 2.在head标签中使用script标...

  • JS运行机制

    JS运行机制 如果一个文档流中包含多个script代码段(用script标签分隔的js代码或引入的js文件),运行...

  • JS

    [TOC] 1. js的声明和引入 在head标签中使用script标签声明js代码域 在head标签中使用scr...

  • 一、JS代码插入方法 1.使用标签在html网页文档中插入javascript代...

  • 枫子翰专属JavaScript笔记

    未完成 引入JS的方式 在HTML中直接引入: JS代码 使用script标签导入JS文件: 使用lin...

  • JS 学习笔记 | 变量篇

    1.名称解释与变量 script 标签表示脚本,可以在 script 标签中编写 js 代码也可以通过 scrip...

  • js基础——使用方式

    一、使用方式: 1.1、使用script标签,在标签内写js语句(注意:每句都加分号;) 1.2、使用js文件:在...

  • 生成二维码

    引入依赖 template script 不使用 因为base64过长,造成点击a标签时无反应

  • 模板渲染template

    template官网 1.使用方法 引入templa.js文件 在页面新建一个div占据渲染的位置 必须使用id命名

网友评论

      本文标题:使用script或template标签:分离js代码templa

      本文链接:https://www.haomeiwen.com/subject/sgyzkctx.html