ChingFeng
Sep 1, 2018 · 2 min read

VueJs元件篇-component(二)

參數值

◉語法

Vue.component('名稱',{
template:`html樣版`,
props:['...'],
data(){
return {
資料1: xxx
...
}
}
});

說明:
props:參數宣告陣列(單向綁定)。
data:資料宣告(注意:component的資料宣告是return function)

◉應用-使用component參數

=【Html】=
— — — — — — — — — — — —
<div id="app">
<label>Sound level</label>
<input type="number" v-model:number="soundLevel">
<sounnd-icon :level="soundLevel"></sounnd-icon>
</div>
— — — — — — — — — — — —
=【VueJs】=
— — — — — — — — — — — —
Vue.component(
'sounnd-icon',
{
template: "<span>{{soundEmojis[level]}}</span>",
props: ['level'],
data(){
return {
soundEmojis: ['🔇', '🔈', '🔉', '🔊']
}
}
}
);
new Vue({
el:'#app',
data:{
soundLevel: 0
}
});

Object實戰

學習歷程紀錄

ChingFeng

Written by

叢林般的世界,一步步邁向未知的未來,迴盪迷途的工程師…

Object實戰

學習歷程紀錄

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade