Creating reuable components
Vue.compent('price', {
data: function() {
return {
prefix: '$',
value: 22.34,
precision: 2
}
},
template: '<span> {{ this.prefix + Number.paseFloat(this.value).toFixed(this.precision) }} </span>'
});
//HTML
//You can now use it with <price></price>
Using Props
- like an HTML variable
- simple as array of things
//HTML
<div>
<price
:value="item.price",
:prefix="'€'",
:precision="2",
:conversion="0.87"></price>
</div>
//JS
Vue.compent('price', {
data: function() {
return {
prefix: '$',
value: 22.34,
precision: 2
}
},
props: ['value', 'prefix', 'precision', 'conversion'],
template: '<span> {{ this.prefix + Number.paseFloat(this.value).toFixed(this.precision) }} </span>'
});
Prop Options:
props: {
value: Number,
prefix: {
type: String,
default: '$'
},
precision: {
type: Number,
default: 2
},
conversion: {
type: Number,
default: 2
}
},
- It allows to set values and make default values as well.
Emit Options:
- Pass along the name of the events
'Vue.js' 카테고리의 다른 글
[Vuex] Vuex Intro (0) | 2022.05.13 |
---|---|
[Vue.js] Vue-Cli and other tools (0) | 2022.05.12 |
[Vue.js] Deleting Items and Modifiers (0) | 2022.05.11 |
[Vue.js] Adding computed classes (0) | 2022.05.11 |
[Vue.js] Categorizing lists (0) | 2022.05.11 |