【发布时间】:2019-03-09 18:02:56
【问题描述】:
我的查看页面代码
<div id="app">
@{{ msg }}
@{{ content }}
在此处使用表单
<form method="post" enctype="multipart/form-data" v-on:submit.prevent="addPost">
<textarea v-model="content" id="postText" class="form-control"></textarea>
<button type="submit" id="postBtn">Post</button>
</form></div>
这是我的 app.js 代码
const app = new Vue({
el: '#app',
在此处返回数据 数据: { 返回:{ msg: '发帖:', 内容: '', bUrl: 'http://localhost:8888/pathikhome', } }, 方法: { 获取 addpost 数据
addPost(){
axios.post(this.bUrl +'/addPost', {
content: this.content
})
.then( (response) =>{
this.content="";
console.log('saved successfully'); // show if success
if(response.status===200){
app.posts = response.data;
}
})
.catch(function (error) {
console.log(error); // run if we have error
});
}
}
});
【问题讨论】:
-
加载数据后你正在做
app.posts = response.data。什么是app?!