lna*_*mba 14 vue.js vue-router vue-component axios vuejs2
我很难用Vue-Router传递道具.当我将它们带入下一个视图时,我似乎无法访问道具.这是我的方法对象:
methods: {
submitForm() {
let self = this;
axios({
method: 'post',
url: url_here,
data:{
email: this.email,
password: this.password
},
headers: {
'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'
}
}).then(function(response) {
self.userInfo = response.data;
self.$router.push({name: 'reading-comprehension', props: {GUID:self.userInfo.uniqueID }});
})
}
}
Run Code Online (Sandbox Code Playgroud)
post请求正在运行,但当我尝试路由到一个新组件并传入一个props来访问下一个组件时,它说,
属性或方法"guid"未在实例上定义,但在呈现期间引用.确保在数据选项中声明反应数据属性.
顺便说一句,我路由到的组件看起来像这样:
<template lang="html">
<div class="grid-container" id="read-comp">
<div class="row">
<h1>Make a sentence:</h1>
{{ GUID }}
</div>
</div>
</template>
<script>
export default {
data(){
return {
props: ['GUID'],
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ber*_*ert 33
当您以编程方式导航到新路线时,您应该使用params
而不是道具.
self.$router.push({name: 'reading-comprehension', params: {guid:self.userInfo.uniqueID }});
Run Code Online (Sandbox Code Playgroud)
其次,在路由定义中,应将该props
属性设置为true.
{name: "reading-comprehension", component: SomeComponent, props: true }
Run Code Online (Sandbox Code Playgroud)
最后,在您的组件中,您将props
单独定义data
,它应该全部为小写.
export default {
props: ["guid"],
data(){
return {
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16026 次 |
最近记录: |