vue使用props在组件中传输和接收参数

vue使用props在组件中传输和接收参数,第1张

1、在组件中使用props选项定义数据,接收参数

2、在路由中,使用props选项来进行设置,路由中的props有三种模式

a、布尔模式:props设置为true,可接收params方式的参数传递;

{

path:"bjc/:name/:price",//定义其属性

component:Bjc,

props:true

},

接收参数:

props: {

keyword: {

type: String,

default: ''

}

},

在浏览器中的表现形式: www.qijinn.com/item/search/1/2

b、函数模式:props为函数,可接收query方式参数的传递;

路由定义: {

path: '/items/search/result',

name: 'search-result',

meta: {

keepAlive: true

},

component: asyncLoader('items/search-result'),

props: route =>route.query

},

传递参数:

this.$router.push({

name: 'search-result',

query: { keyword: word.trim() }

})

接收参数:

props: {

keyword: {

type: String,

default: ''

}

},

在浏览器中的表现形式: www.qijinn.com/item/search/result?keyword= 七堇年

c、对象模式:props为对象。如果处理静态数据,可使用对象模式;

{

path:"yc",

component:Yc,

props:{

name:'蜜汁叉烧量版式',

price:648

}

},

接收参数:

props: {

keyword: {

type: String,

default: ''

}

},

结构体的初始化一定要按照结构定义的顺序进行。

把那个 .gold= 和 .bag.max= 删掉,调整成如下的形式初始化

{1,"超级毛毛虫","123456",.gold=5000,.bag.max=8},

==>注意顺序,bag中后面的可省略,前面的要提供

{1,"超级毛毛虫","123456",{0,0,8},5000},


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/7913684.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-11
下一篇2023-04-11

发表评论

登录后才能评论

评论列表(0条)

    保存