(0 , _stores_token_js__WEBPACK_IMPORTED_MODULE_3__.useTokenStore) is not a function TypeError: (0 , _stores_token_js__WEBPACK_IMPORTED_MODULE_3__.useTokenStore) is not a function at setup (webpack-internal:///./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/views/testLogin.vue?vue&type=script&setup=true&lang=js:24:82) at callWithErrorHandling (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:326:18) at setupStatefulComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:6706:25) at setupComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:6667:36) at mountComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:5220:7) at processComponent (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:5198:9) at patch (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:4873:11) at ReactiveEffect.componentUpdateFn [as fn] (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:5397:9) at ReactiveEffect.run (webpack-internal:///./node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:216:19) at instance.update (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:5428:16)
意思是:useTokenStore不是函数
(0,_ stores _ token _ js _ _ web pack _ IMPORTED _ MODULE _ 3 _ _)。useTokenStore)不是函数 类型错误:(0,_ stores _ token _ js _ _ web pack _ IMPORTED _ MODULE _ 3 _ _。useTokenStore)不是函数 安装时(webpack-internal:///)。/node _ modules/babel-loader/lib/index . js??clonedRuleSet-40 . use【0】!。/node _ modules/vue-loader/dist/index . js??规则集【0】。使用【0】!。/src/views/testLogin.vue?vue & type = script & setup = true & lang = js:24:82) at callWithErrorHandling(web pack-internal:///)。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:326:18) 位于setupStatefulComponent(web pack-internal:///)。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:6706:25) at setup component(web pack-internal:///)。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:6667:36) 安装组件时(webpack-internal:///。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:5220:7) at process component(web pack-internal:///。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:5198:9) 安装补丁(webpack-internal:///)。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:4873:11) at react ive effect . component updatefn【as fn】(web pack-internal:///。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:5397:9) at react ive effect . run(web pack-internal:///)。/node _ modules/@ vue/reactivity/dist/reactivity . ESM-bundler . js:216:19) at instance . update(web pack-internal:///)。/node _ modules/@ vue/runtime-core/dist/runtime-core . ESM-bundler . js:5428:16)
控制台也出现了这个函数不是函数的意思
main.js的配置
import { createApp } from 'vue' import { QuillEditor } from '@vueup/vue-quill' import '@vueup/vue-quill/dist/vue-quill.snow.css'; import App from './App.vue' import router from '@/router' import { createPinia } from 'pinia' import { createPersistedState } from 'pinia-persistedstate-plugin' // import editor from '@/views/editorViewDemo.vue' // main.ts import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' import locale from 'element-plus/theme-chalk/index.css' const app = createApp(App); const pinia = createPinia(); const persist = createPersistedState(); pinia.use(persist) app.use(pinia) // require styles // const app = createApp(App) // app.component('editorView', editor) // app.component('QuillEditor', editor) // 这个地方可能出问题 createApp(App).component('QuillEditor', QuillEditor).use(router).use(scroll).use(ElementPlus, { locale }).mount('#app')
token.js的配置
//定义store import { defineStore } from 'pinia' import { ref } from 'vue' /* 第一个参数:名字,唯一性 第二个参数:函数,函数的内部可以定义状态的所有内容 返回值: 函数 */ export const useTokenStore = defineStore('token', () => { //定义状态的内容 //1.响应式变量 const token = ref('') //2.定义一个函数,修改token的值 const setToken = (newToken) => { token.value = newToken } //3.函数,移除token的值 const removeToken = () => { token.value = '' } return { token, setToken, removeToken } }, { persist: true//持久化存储 });
testLogin导入的配置
<script setup> import { ref } from 'vue' //调用后台接口,完成注册 import { userLoginService } from '@/api/user.js' import { ElMessage } from "element-plus"; import router from '@/router'; import { useTokenStore } from '@/stores/token.js' // const store = useTokenStore(); // const tokenStore = useTokenStore(); const tokenStore = useTokenStore(); const login = async () => { //registerData是一个响应式对象,如果要获取值,需要.value let result = await userLoginService(registerData.value); // if (result.code === 0) { // //成功了 // alert(result.msg ? result.msg : '登录成功'); // } else { // //失败了 // alert('登录失败') // } ElMessage.success(result.data.msg ? result.data.msg : '登录成功') // store.setToken(result.data) tokenStore.setToken(result.data) router.push('/editor') } // 定义数据模型 const registerData = ref({ username: '', password: '', rePassword: '' }) </script> <template> <el-row class="login-page"> <el-col :span="12" class="bg"></el-col> <el-col :span="6" :offset="3" class="form"> <!-- 注册表单 --> <el-form ref="form" size="large" autocomplete="off" :model="registerData"> <el-form-item> <h1>登录</h1> </el-form-item> <el-form-item prop="username"> <el-input placeholder="请输入用户名" v-model="registerData.username"></el-input> </el-form-item> <el-form-item prop="password"> <el-input type="password" placeholder="请输入密码" v-model="registerData.password"></el-input> </el-form-item> <!-- 注册按钮 --> <el-form-item> <el-button class="button" type="primary" auto-insert-space @click="login"> 登录 </el-button> </el-form-item> </el-form> <!-- 登录表单 --> </el-col> </el-row> </template> <script> export default { } </script> <style></style>