当 console.logging 出错时,浏览器会打印与普通对象不同样式的输出。如何强制 Google / Firefox 打印 Error 类的真实对象,而不是程式化的不太有用的“错误”输出?
例如,我知道该对象包含e.message和e.response例如,您永远无法从浏览器日志输出中推断出它。
api
.post('/post/create', formData)
.then((res) => {
})
.catch((e) => {
// doesn't print the error object
// doesn't print the error object
// doesn't print the error object
console.log(e)
// UPDATE, destructuring does print the full Error object
// UPDATE, destructuring does print the full Error object
// UPDATE, destructuring does print the full Error object
console.log('full error object', {e})
})
Run Code Online (Sandbox Code Playgroud)
批准答案后更新。现在我得到了完整的错误对象。
我们正在部署一个基于 PHP 后端的前端 Vue 应用程序。当我们部署新版本的 Vue 应用程序代码时,我们的客户端总是卡在旧代码上,除非他们执行硬刷新/清除缓存/隐身模式。
如何强制浏览器刷新之前部署中的所有缓存内容?
刷新第一页时,asyncData 函数无法获取持久状态。当我关注另一个 NuxtLink 并返回到此页面时,虽然状态在此期间没有发生变化,但数据就在那里。这意味着持久状态在第一次加载/刷新时在服务器端不可用。LocalStorage 是我选择保存相关状态项的地方。
使用 asyncData 的页面组件:
asyncData({ app, params, store }) {
//its not available upon first refresh, but is after following a random nuxtlink and going back
const cartProducts = store.getters.getCartProducts
},
Run Code Online (Sandbox Code Playgroud)
store/index.js 很简单。不幸的是,在第一页刷新时,asyncData 中的状态完全为空。
getCartProducts(state) {
return state.cart.products
},
Run Code Online (Sandbox Code Playgroud)
按照 Github 自述文件中的建议,使用“客户端”模式正确导入 vuex-persist.js
import VuexPersistence from 'vuex-persist'
/** https://github.com/championswimmer/vuex-persist#tips-for-nuxt */
export default ({ store }) => {
window.onNuxtReady(() => {
new VuexPersistence({
key: 'cartStorage'
/* your options */
}).plugin(store)
})
}
Run Code Online (Sandbox Code Playgroud)
如何确保在调用 asyncData之前保留本地存储中的相关存储术语?