前后端数据交互-----ncaught (in promise) TypeError: this.registerAPI is not a function

简介: 前后端数据交互-----ncaught (in promise) TypeError: this.registerAPI is not a function

        今天在敲代码的时候,又爆了一个bug

       Uncaught (in promise) TypeError: this.registerAPI is not a function,这句话的意思是??这句话的意思是?自己写的form表单

       未捕获(在承诺中)类型错误:this.registerAPI不是函数

        <el-form ref="form" :model="form" :rules="regRules">
            <el-form-item prop="username">
                <el-input placeholder="请输入用户名" v-model="form.username"></el-input>
            </el-form-item>
            <!-- 密码 -->
            <el-form-item prop="password">
                <el-input type="password" placeholder="请输入密码" v-model="form.password"></el-input>
            </el-form-item>
            <!-- 确认密码 -->
            <!-- 注册按钮 -->
            <el-form-item>
                <el-button class="button" type="primary" auto-insert-space @click="register">
                    注册
                </el-button>
            </el-form-item>
            <el-form-item>
                <el-link type="info">
                    ← 返回
                </el-link>
            </el-form-item>
        </el-form>

methods的方法:

export default {
    data() {
        return {
            form: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        // js兜底校验
 
        register() {
            this.$refs.form.validate(async valid => {
                if (valid) {
                    console.log(this.form)
                    const { data: res } = await this.registerAPI(this.form)
                    console.log(res)
                    if (res.code !== 0) return this.$message.error(res.message)
                    // 注册成功,提示用户
                    this.$message.success(res.message)
                    // 跳转到登录页面
                    this.$router.push('/login')
                } else {
                    return false
                }
            })
        }
    }
}

后来出现了看到了解决问题的答案:

这里import没有导入自己的index文件

这里要保证这三者相同,才可以,之前自己粗心写成this导致的


相关文章
|
5月前
|
数据采集 前端开发
突破技术限制:使用 request-promise 库进行美团数据获取
本文展示了如何用`request-promise`爬取美团数据,重点是通过代理IP避免封禁。安装库后,配置含代理的请求选项,如`proxy`, `auth`和`headers`,并用`cheerio`解析HTML获取餐厅菜单。通过代理服务可以提高爬虫效率。
141 0
突破技术限制:使用 request-promise 库进行美团数据获取
|
4月前
|
前端开发 小程序 JavaScript
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
|
2月前
|
缓存
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
|
2月前
【Azure 事件中心】在Azure Function App中消费Event Hub数据,时常出现EventReceiveError
【Azure 事件中心】在Azure Function App中消费Event Hub数据,时常出现EventReceiveError
|
2月前
|
前端开发 JavaScript
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
32 0
|
3月前
|
前端开发
Error in created hook: “TypeError: _test.default is not a function
Error in created hook: “TypeError: _test.default is not a function
|
3月前
|
前端开发 JavaScript 定位技术
JavaScript 等待异步请求数据返回值后,继续执行代码 —— async await Promise的使用方法
JavaScript 等待异步请求数据返回值后,继续执行代码 —— async await Promise的使用方法
45 1
|
3月前
|
前端开发 JavaScript
Promise 等待多个接口返回数据再执行操作
Promise 等待多个接口返回数据再执行操作
40 0
|
5月前
|
数据库
element多选框select下拉框数据回显的问题value.push is not a function
element多选框select下拉框数据回显的问题value.push is not a function
337 1
|
5月前
|
缓存
pytest 运行测试函数报错的解决办法 TypeError: calling <function xxx> returned None, not a test
pytest 运行测试函数报错的解决办法 TypeError: calling <function xxx> returned None, not a test
298 0