我的问题是,当我使用setup时,我不能在正常脚本中访问它,但只有在我以开发模式构建应用程序后,一切都正常。在本例中,我不能在我的logout函数中访问这个.authStore。
`
<script setup>
import { ref } from "vue";
import { storeToRefs } from "pinia";
import { useAuthStore } from "@/stores/auth-store";
const authStore = useAuthStore();
const { user } = storeToRefs(authStore);
const searchDropdown = ref(false);
const showSearchDropdown = () => {
searchDropdown.value = true;
};
const hideSearchDropdown = () => {
searchDropdown.value = false;
};
</script>
<script>
export default {
name: "Top Bar",
data() {
return {
pageName: this.$route.name,
};
},
methods: {
async logout() {
await this.authStore.logout();
},
},
};
</script>
`
1条答案
按热度按时间gpnt7bae1#
尝试只使用组合API来使代码一致,用函数替换
logout
方法,使用useRoute
获取路由名称: