vue使用props在組件中傳輸和接收參數(shù)

1、在組件中使用props選項(xiàng)定義數(shù)據(jù),接收參數(shù);
2、在路由中,使用props選項(xiàng)來進(jìn)行設(shè)置,路由中的props有三種模式:
a、布爾模式:props設(shè)置為true,可接收params方式的參數(shù)傳遞;
{
path:"bjc/:name/:price",//定義其屬性
component:Bjc,
props:true
},
接收參數(shù):
props: {
keyword: {
type: String,
default: ''
}
},
在瀏覽器中的表現(xiàn)形式:www.qijinn.com/item/search/1/2
b、函數(shù)模式:props為函數(shù),可接收query方式參數(shù)的傳遞;
路由定義: {
path: '/items/search/result',
name: 'search-result',
meta: {
keepAlive: true
},
component: asyncLoader('items/search-result'),
props: route => route.query
},
傳遞參數(shù):
this.$router.push({
name: 'search-result',
query: { keyword: word.trim() }
});
接收參數(shù):
props: {
keyword: {
type: String,
default: ''
}
},
在瀏覽器中的表現(xiàn)形式: www.qijinn.com/item/search/result?keyword=七堇年

c、對象模式:props為對象。如果處理靜態(tài)數(shù)據(jù),可使用對象模式;
{
path:"yc",
component:Yc,
props:{
name:'蜜汁叉燒量版式',
price:648
}
},

接收參數(shù):
props: {
keyword: {
type: String,
default: ''
}
},

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容