新建一个普通的uni-app项目
index.vue页面代码
<template>
<view class="container">
<view v-for="(user,index) in users" :key="index">
<view>学号:{{user.id}}=====索引:{{index}}</view>
<view>姓名:{{user.name}}</view>
<hr>
</view>
</view>
</template>
<script>
export default {
data() {
return {
users:[]
}
},
// 建议使用 uni-app 的 onLoad 代替 vue 的 created
onLoad: function() {
this.getUsers();
},
methods: {
getUsers: function() {
var _this= this;
// 详见官网:https://uniapp.dcloud.io/api/request/request
uni.request({
// url:'http://localhost:8888/api/getAll',
url:this.apiServer+'/getAll',
method: 'GET',
header: { 'content-type': 'application/x-www-form-urlencoded'},
success: res => {
_this.users = res.data;
}
});
}
}
};
</script>
<style>
</style>
main.js添加这行代码
Vue.prototype.apiServer = 'http://localhost:8888/api'
这里用的后端接口是之前的,详见