按视频教程5-8搭建后台后,无法通过路由获取后台数据,好像执行不到路由的入口那里去。
//App.vue里面的内容
<script>
import {get} from './util'
export default {
async created () {
const res = await get('/weapp/demo')
console.log(123, res)
console.log('小程序启动了')
}
}
</script>
<style>
</style>
//config.js的内容
const host = 'https://fnus5zmo.qcloud.la'
const config = {
host
}
export default config
//util.js的内容
import config from './config'
export function get (url) {
return new Promise((resolve, reject) => {
wx.request({
url: config.host + url,
success: function (res) {
if (res.data.code === 0) {
resolve(res.data.data)
console.log('res.data.code === 0')
console.log(res)
} else {
reject(res.data)
console.log('res.data.code != 0')
}
}
})
})
}
//index.js添加路由如下
router.get('/demo', controllers.demo)
//demo.js内容如下
module.exports = async (ctx) => {
ctx.state.data = {
msg: 'hello 小程序后台'
}
console.log('执行到后台')
}
打印的数据如下(随便用一个路由名字调用都是一样的结果 get('/weapp/demo888')):
res.data.code === 0
util.js:12 {data: {…}, header: {…}, statusCode: 200, errMsg: "request:ok"}
data: code: 0
data: {}
__proto__: Object
errMsg: "request:ok"header: {Server: "nginx/1.10.2", Date: "Sun, 24 Jun 2018 18:05:01 GMT", Content-Type: "application/json; charset=utf-8", Content-Length: "20", Connection: "keep-alive"}statusCode: 200__proto__: Object
App.vue:6 123 {}
App.vue:7 小程序启动了
是不是服务器哪里设置有问题呀,谢谢