记录flask和vue的前后端交互:
python使用flask作为后端,前端使用vue框架搭建界面,使用axios方法实现前后端数据交互,一个交互的小demo
前端:
点击按钮,运行test方法,将input输入通过page传输到后端,返回的数据显示到text
<input type= 'text' v-model="page" placeholder="edit me">
<button @click="test()">CheckThis</button>
<li>{
{ text }}</li>
axios方法,传输page到后端,返回数据为res.data ,后端端口为:http://127.0.0.1:5000
test(){
axios.post('http://127.0.0.1:5000/test',{"name":this.page})
.then(res=>{
this.text = res.data; //返回数据显示到text
console.log(res.data);// 返回的数据
alert(this.text);
})
.catch(err=>{
this.text = 'error' + err;