老师你好,我在调用get和post方法的时候报错了。报错信息都是一样的。
vendor.js:17 Uncaught TypeError: __webpack_require__(...) is not a function
at Object.<anonymous> (vendor.js:17)
at __webpack_require__ (manifest.js:59)
at Object._ (main.js:32)
at __webpack_require__ (manifest.js:59)
at Object.<anonymous> (vendor.js:6922)
at __webpack_require__ (manifest.js:59)
at Object.<anonymous> (vendor.js:6899)
at __webpack_require__ (manifest.js:59)
at Object.<anonymous> (vendor.js:6892)
at __webpack_require__ (manifest.js:59)
我的代码:
/src/utils/request.js
function createFly() {
// mpvuePlatform 是一个全局变量,平台类型
if (mpvuePlatform === 'wx') {
const Fly = require('flyio/dist/npm/wx')
return new Fly()
} else {
// 其他的平台暂不支持
return null
}
}
function handleError(err) {
console.log(err)
}
export function get(url, params = {}) {
const fly = createFly()
if (fly) {
return new Promise((resolve, reject) => {
fly.get(url, params).then(response => {
console.log(response)
resolve(response)
}).catch(err => {
console.log(err)
handleError(err)
reject(err)
})
})
}
}
export function post(url, params = {}) {
const fly = createFly()
if (fly) {
return new Promise((resolve, reject) => {
fly.post(url, params).then(response => {
console.log(response)
resolve(response)
}).catch(err => {
console.log(err)
handleError(err)
reject(err)
})
})
}
}
调用
<template>
<div>
<div class="font-color">
Hello World
</div>
<van-button type="primary" @click="jump">按钮</van-button>
</div>
</template>
<script>
import { post } from '../../utils/request'
export default {
methods: {
jump(){
post('http://www.baidu.com').then(res => {
console.log(res.data)
})
}
}
}
</script>
<style scoped lang="stylus">
.font-color
color: red
font-size 20px
font-weight bold
</style>
组件版本
"flyio": "^0.6.14",
"mpvue": "^2.0.0",
"mpvue-router-patch": "^2.0.0",
"vant-weapp": "^0.5.17",
"vuex": "^3.0.1"