Vue之props 配置詳解
更新時間:2021年11月21日 14:31:30 作者:王同學(xué)要努力
這篇文章主要為大家介紹了Vue之props 配置,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助,希望能夠給你帶來幫助

<template>
<div class="demo">
<h1>{{ msg}}</h1>
<h2>學(xué)生姓名:{{name}}</h2>
<h2>學(xué)生性別:{{sex}}</h2>
<h2>學(xué)生的年齡:{{myage+1}}</h2>
<button @click="changeAge">點我修改數(shù)據(jù)</button>
</div>
</template>
<script>
export default {
name: 'Student',
data() {
return {
msg: '王者愛好者',
myage:this.age
}
},
methods: {
changeAge(){
this.myage=24
}
},
//簡單接收
// props:['name','age','sex']
//接收的同時對數(shù)據(jù)進(jìn)行類型的限制
// props:{
// name:String,
// age:Number,
// sex:String,
// }
//接收數(shù)據(jù)的同時對數(shù)據(jù):進(jìn)行類型的限定+默認(rèn)值的指定+必要性的限制
props: {
name: {
type: String, //name的類型
required: true, //name是必要的
},
age: {
type: Number,
default:22
},
sex: {
type: String,
required: true
}
}
}
</script>
<template>
<div>
<Student name="張三" sex="男" :myage="20"/>
</div>
</template>
<script>
//引入Student組件
import Student from './components/Student.vue'
export default {
name: 'App',
components: {
Student
}
}
</script>
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
vue鼠標(biāo)移入添加class樣式,鼠標(biāo)移出去除樣式(active)實現(xiàn)方法
今天小編就為大家分享一篇vue鼠標(biāo)移入添加class樣式,鼠標(biāo)移出去除樣式(active)實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
利用vue重構(gòu)有贊商城的思路以及總結(jié)整理
這篇文章主要介紹了利用vue重構(gòu)有贊商城的思路以及總結(jié)整理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-02-02
基于vue實現(xiàn)分頁/翻頁組件paginator示例
本篇文章主要介紹了基于vue實現(xiàn)分頁/翻頁組件paginator示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03

