【发布时间】:2018-01-20 16:27:13
【问题描述】:
我构建了以下组件:
var Modal = Vue.component('modal', {
template: `
<div id="modal" class="modal">
<div class="modal-content">
<p>{{ link }}</p>
</div>
</div>
`,
props: [
'link'
],
});
我想在我成功发送 axios 帖子后动态更改链接数据。
我的 vue 实例
new Vue({
el: '#form',
components: {
'modal': Modal
},
data: {
userId: '',
title: '',
body: '',
snippetLink: '',
},
methods: {
publish (e) {
var self = this;
axios.post('/snippets', {
title: this.title,
body: this.content,
})
.then(function (response) {
console.log("success");
self.link = response.data.hash; // Here I tried to add the reponse content to the vue component's p
})
.catch(function (error) {
console.log(error);
})
},
我的 HTML 标记:
<modal link=""></modal>
...
<button type="button"
v-bind:class="{ 'modal-trigger': !isActiveModal }"
@click="publish">Publish
<i class="material-icons right">send</i>
</button>
所以我成功地将 axios 帖子发送到我的服务器并获取数据,我想打开一个模态窗口并将数据放在 p 标签中,到目前为止,模态在我的帖子之后弹出,但我不确定我的它不会改变 p 标签的内容。
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component