[英]Vue - Is it fine to store a value in session storage rigth from the main.js file?
So I have a session storage value set to false that I need to keep track of for the user session that is managed by Vuex.因此,我将 session 存储值设置为 false,我需要跟踪由 Vuex 管理的用户 session。 I set up the value right from the main.js file as such:
我直接从 main.js 文件中设置值:
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import axios from 'axios';
import store from './store'
createApp(App).use(store).use(router).mount('#app')
sessionStorage.setItem('session', false);
App.prototype.$http = axios
And I was wondering whether it was ok to do it as such right from main.js file or if vuzI should do it elsewhere, such as in App.vue.我想知道直接从 main.js 文件这样做是否可以,或者我是否应该在其他地方这样做,比如在 App.vue 中。
Thanks in advance提前致谢
that's ok,the code runs well, you can use sessionStorage.setItem
anywhere,because this is a synchronous method.没关系,代码运行良好,你可以在任何地方使用
sessionStorage.setItem
,因为这是一个同步方法。 if it goes badly, there must be something wrong with the logic of the code, i need more clues.如果出现问题,代码的逻辑一定有问题,我需要更多线索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.