vue + ajax + php 接口的使用小接
前端代码: (获取用户信息,并渲染页面)userinfor.html
用户信息{ {item.userName}} { {item.userTel}}
new Vue({
el: '#app',
data: {
userList: []
},
created: function () {
var that = this;
$.ajax({
type : "POST",
url : "./userinfor.php",
data : "",
success : function( data ) {
var json = JSON.parse(data);
if (json.flag) {
that.userList = json.datalist;
} else {
alert(json.error_code);
}
},
error : function(){
lert("错误");
}
})
},
})
PHP代码: (查询数据库,并形成接口输出) userinfor.php
header("Content-type: text/html; c