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: ''
}
},