【发布时间】:2017-04-28 04:32:42
【问题描述】:
我的项目使用 laravel 作为后端,使用 vue 作为前端。 我想将道具 id 传递给方法。 然后,当我单击按钮时,它将获取用户 ID 并运行继续进程。
在我看来,我使用它来将 id 传递给 vue 组件。
<conversation_send_message_form user_id="{{ $user->id }}"></conversation_send_message_form>
之后这是我的 vue 代码
export default {
data() {
return {
body: null,
recipients: [],
}
},
props: ['id'],
methods: {
...mapActions([
'sendMessage'
]),
send(){
this.sendMessage({
recipientIds: this.id,
body: this.body
}).then(() =>{
this.recipients= []
this.body = null
})
}
}
}
这里会接收数据并进行处理
sendMessage ({dispatch, commit}, {body, recipientIds}) {
return api.storeMessage({
body: body,
recipientIds: recipientIds
}).then((response) => {
console.log(response)
})
},
我的 API
storeMessage({body, recipientIds}){
return new Promise((resolve, reject) => {
axios.post('/webapi/conversations', {
body: body,
recipients: recipientIds
}).then((response) =>{
resolve(response)
})
})
},
在我的场景中,我需要一个新方法来获取道具 id 并传递给新方法“Send”,在其中将 id 传递给接收者Ids,然后 api 将处理它。但我不知道如何获得道具 ID。谁能帮帮我?
【问题讨论】:
-
您可以使用“this”访问方法内的数据。例如,this.id 将是存储在 id 属性中的数据。
标签: javascript php laravel vue.js