iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 14
0
自我挑戰組

使用Vue製作簡單的 WorkBoard (30天)系列 第 14

(第十四天)自我學習 - component 第二次學習

component 資料顯示

在第一次學習 component 的時候,只有標籤可以使用,但是這次有學到如何在 component 顯示 data 裡面的資料。


先來做 component

//新增新的 tag 命名為 today-weather
Vue.component('today-weather', {
    template: '<strong>{{ todayWeather }}</strong>',
    //可以在 component 裡面在新增一個 data 裡面可以放需要使用的參數
    data: function(){
        return {
            todayWeather: '大晴天'
        };
    }
});
//這裡一樣需要 new 一個 Vue 的檔案
var myApp = new Vue({
    el: '#myApp', 
});
//需要在 myApp 裡面新增標籤
<div id="myApp">
    //使用剛剛新增的 today-weather 標籤
    <div>今天天氣<today-weather/></div>
</div>

這樣是不是就可以顯示出 component 裡面的東西了呢?


上一篇
(第十三天)自我學習 - 下拉式選單
下一篇
(第十五天)自我學習 - component Table 標籤使用
系列文
使用Vue製作簡單的 WorkBoard (30天)24
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言