无效问题 #1648
Unanswered
JackingZ
asked this question in
Help and Questions
无效问题
#1648
Replies: 1 comment
-
This problem has been resolved |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
user.ts (document)
import { defineStore } from 'pinia'
type role = string[]
export const userStore = defineStore('user', {
state: () => ({
token: '',
roles: []
}),
getters: {
roles: (state) => state.roles,
token: (state) => state.token
},
actions: {
login() {
console.log("xxx")
this.token = '1234567890qwertyuiop'
},
getUserInfo() {
this.roles = ['organzier', 'role', 'user', 'company']
}
}
})
login.vue(document)
`<script setup lang="ts">
import { reactive, ref, Ref } from 'vue'
import { FormInst, FormItemRule } from 'naive-ui'
import { userStore } from '@/store/user'
import { useRouter } from 'vue-router'
const router = useRouter()
const userStoreData = userStore()
const submit = (e) => {
userStoreData.login()
console.log(userStoreData)
此处可以获取到对象,但是login方法调用失败,无法打印出xxx,是什么原因???
router.push('/xxx')
userFormRef.value?.validate((errors) => {
if (!errors) {
// 验证成功
} else {
console.log(errors)
// 验证失败
}
})
}
</script>`
Beta Was this translation helpful? Give feedback.
All reactions