Vue中如何书写js来渲染页面填充数据的部分代码

Posted 小猪_佩奇

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vue中如何书写js来渲染页面填充数据的部分代码相关的知识,希望对你有一定的参考价值。


new Vue({
el:"#app" ,
data:{
user:{
id:"",
username:"",
password:"",
age:"",
sex:"",
},
userList:[]
},
methods:{
findAll:function () {
//在当前方法中定义一个变量,表明是vue对象
var _this= this;
axios.get(‘/day01_eesy_vuejsdemo/user/findAll.do‘)
.then(function (response) {
// handle success
_this.userList=response.data;
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
},
findById:function (userid) {
//在当前方法中定义一个变量,表明是vue对象
var _this= this;
axios.get(‘/day01_eesy_vuejsdemo/user/findById.do‘,{params:{id:userid}})
.then(function (response) {
// handle success
_this.user=response.data;
$("#myModal").modal("show");
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
},
update:function (user) { //post请求
//在当前方法中定义一个变量,表明是vue对象
var _this= this;
axios.post(‘/day01_eesy_vuejsdemo/user/updateUser.do‘, _this.user)
.then(function (response) {
_this.findAll();
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
},
created:function(){
this.findAll();
}
});
 

以上是关于Vue中如何书写js来渲染页面填充数据的部分代码的主要内容,如果未能解决你的问题,请参考以下文章

如何使用来自 CMS 的服务器端渲染内容来补充 Vue.js?

记录在ios系统上,自研app,灰度环境遇到的一个vue页面dom节点已渲染,但是显示部分空白的情况

如何使用AngularJS重新加载或渲染整个页面

Vue.js - 组件模板不使用 v-for 渲染

vuejsLearn--- v-for列表渲染

vue.js响应式原理解析与实现