return $key;
}
//简单的测试接口
public function role_show(){
return Db::name('role_power')->select();
}
OK,post方式搞定了,下面是vue使用get方法进行接口调用,渲染数据
简单粗暴,大致一样,就不一一详解了,上代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 软件开发网(mscto.com)</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<body><div id="box">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="width:130px;height:30px;">ROLE_ID</td>
<td style="width:130px;height:30px;">POWER_ID</td>
<td style="width:130px;height:30px;">创建时间</td>
</tr>
<tr v-for="v in msg">
<td style="width:130px;height:30px;">{{v.role_id}}</td>
<td style="width:130px;height:30px;">{{v.power_id}}</td>
<td style="width:130px;height:30px;">{{v.create_time}}</td>
</tr>
</table>
</div>
<script type = "text/javascript">
window.onload = function(){
var vm = new Vue({
el:'#box',
data:{
msg:'',
},
mounted:function () {
this.get();
},
methods:{
get:function(){
//发送get请求
this.$http.get("http://ip?key=密钥",{emulateJSON:true}).then(function(res){
console.log(res.body);
this.msg=res.body.data;
},function(){
console.log('请求失败处理');
});
}
}
});
}
</script>
</body>
</html>
ok,都测试好了,可以使用,千万别搞错id哦。
以上这篇使用Vue调取接口,并渲染数据的示例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。










