国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

3種vue組件的書寫形式

2019-11-19 14:49:16
字體:
來源:轉載
供稿:網友

本文實例為大家分享了vue組件的書寫形式,供大家參考,具體內容如下

第一種使用script標簽

<!DOCTYPE html><html>  <body>    <div id="app">      <my-component></my-component>    </div>    <-- 注意:使用<script>標簽時,type指定為text/x-template,意在告訴瀏覽器這不是一段js腳本,瀏覽器在解析HTML文檔時會忽略<script>標簽內定義的內容。-->    <script type="text/x-template" id="myComponent">//注意 type 和id。      <div>This is a component!</div>    </script>  </body>  <script src="js/vue.js"></script>  <script>    //全局注冊組件    Vue.component('my-component',{      template: '#myComponent'    })    new Vue({      el: '#app'    })  </script></html>

第二種使用template標簽

<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <title></title>  </head>  <body>    <div id="app">      <my-component></my-component>    </div>    <template id="myComponent">      <div>This is a component!</div>    </template>  </body>  <script src="js/vue.js"></script>  <script>    Vue.component('my-component',{      template: '#myComponent'    })    new Vue({      el: '#app'    })  </script></html>

第三種 單文件組件

這種方法常用在vue單頁應用中。詳情看官網:https://cn.vuejs.org/v2/guide/single-file-components.html

創建.vue后綴的文件,組件Hello.vue,放到components文件夾中

<template> <div class="hello">  <h1>{{ msg }}</h1> </div></template><script>export default { name: 'hello', data () {  return {   msg: '歡迎!'  } }}</script>

app.vue

<!-- 展示模板 --><template> <div id="app">  <img src="./assets/logo.png">  <hello></hello> </div></template><script>// 導入組件import Hello from './components/Hello'export default { name: 'app', components: {  Hello }}</script><!-- 樣式代碼 --><style>#app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;}</style>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泽州县| 夹江县| 象山县| 锡林浩特市| 镶黄旗| 桃江县| 平顶山市| 汝南县| 荔浦县| 淮阳县| 河北区| 荥经县| 徐水县| 衡阳县| 合川市| 富源县| 拉萨市| 蓬安县| 乡城县| 康乐县| 黄陵县| 韶关市| 新泰市| 青阳县| 齐齐哈尔市| 汤阴县| 杭锦旗| 鄂温| 亳州市| 弥渡县| 安泽县| 颍上县| 梧州市| 宁海县| 武宁县| 白山市| 喜德县| 天柱县| 抚宁县| 磐安县| 永川市|