Closed landall closed 3 weeks ago
Hi @landall! 👋
It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, StackBlitz, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.
Without a proper reproduction, your issue will have to get closed.
Thank you for your collaboration. 👏
http://74.48.64.200/spa1001/#/
This site is build with quasar build -d
http://74.48.64.200/vue_src.zip
This is the source code.
And which build command can build just the same behavior with quasar dev run
?
It is an issue about useQuasar() in anonymous function in src/router/index.js. It works in dev mode but fails in build mode.
import { route } from 'quasar/wrappers'
import { createRouter, createMemoryHistory, createWebHistory, createWebHashHistory } from 'vue-router'
import routes from './routes'
import { useQuasar } from 'quasar';
/*
* If not building with SSR mode, you can
* directly export the Router instantiation;
*
* The function below can be async too; either use
* async/await or return a Promise which resolves
* with the Router instance.
*/
export default route(function (/* { store, ssrContext } */) {
const createHistory = process.env.SERVER
? createMemoryHistory
: (process.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory)
const Router = createRouter({
scrollBehavior: () => ({ left: 0, top: 0 }),
routes,
// Leave this as is and make changes in quasar.conf.js instead!
// quasar.conf.js -> build -> vueRouterMode
// quasar.conf.js -> build -> publicPath
history: createHistory(process.env.VUE_ROUTER_BASE),
});
Router.beforeEach((to, from, next) => {
const $q = useQuasar();
console.log($q);
console.log(to, from, next, to.meta.area, to.meta.isMemberArea);
var isLogined = checkLogin();
console.log('isLogined=', isLogined);
if ((to.meta.isMemberArea == true) && (isLogined !== true))
{
//$q.localStorage.setItem("preRoute", Router.currentRoute.fullPath);
localStorage.setItem("preRoute", Router.currentRoute.fullPath);
next({ path: '/login' });
}
else
{
//$q.localStorage.remove("preRoute");
localStorage.removeItem("preRoute");
next();
}
});
return Router;
});
Not only index.js, all $q.localStorage report TypeError.
please ref: https://quasar.dev/quasar-plugins/web-storage
import { LocalStorage, SessionStorage } from 'quasar'
LocalStorage.set(key, value)
let value = LocalStorage.getItem(key)
SessionStorage.set(key, value)
let value = SessionStorage.getItem(key)
sorry, a careless mistake. there is no setItem but set....
It confuses me that the methods are getItem & set in Quasar.LocalStorage but getItem&setItem in Html5.
It also confuses me that It is not broken when I use quasar dev run
.
Maybe add a setItem method to be the alias of set is a good choice.
@landall Good point. Added aliases. Will be available in Quasar v2.15.3
What happened?
My site works ok with quasar dev run but white screen with quasar build.
DevTools console show: TypeError: a.localStorage.setItem is not a function at app.ccb5cce6.js:1:1607 at vendor.0daabce7.js:69:13691 at o (vendor.0daabce7.js:69:13423) at vendor.0daabce7.js:69:13682 at new Promise ()
at vendor.0daabce7.js:69:13496
at Object.runWithContext (vendor.0daabce7.js:3:8038)
at N (vendor.0daabce7.js:69:19818)
at vendor.0daabce7.js:69:22842
What did you expect to happen?
works the same with quasar dev run.
Reproduction URL
http://74.48.64.200/spa1000/#/
How to reproduce?
It seems to be a build issue.
Flavour
Quasar CLI with Webpack (@quasar/cli | @quasar/app-webpack)
Areas
Plugins (quasar), SPA Mode
Platforms/Browsers
Chrome
Quasar info output
Relevant log output
Additional context
No response