js 使用script或template標簽:分離js代碼template中的HTML元素


參考: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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM