我正在用Office.js创建一个非常简单的外接程序。我选择Vue和Vue路由器4来创建我的外接程序的前端。以下代码摘自vue路由器指南,只要我不包括Office.js库,它就能工作:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js">只要我在混合浏览器中包括了office.js,这就是我在Chrome控制台和Vue路由器中收到的,不再起作用了:
其中许多是:
[Vue Router warn]: Error with push/replace State TypeError: history[(intermediate value)(intermediate value)(intermediate value)] is not a function
at changeLocation (vue-router@4:514:62)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)其中之一是:
Uncaught RangeError: Maximum call stack size exceeded.
at changeLocation (vue-router@4:522:55)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)
at replace (vue-router@4:529:11)
at popStateHandler (vue-router@4:405:15)
at changeLocation (vue-router@4:522:55)此代码将重现此问题:
<!DOCTYPE html>
<html>
<body>
<div id="app">
<p>
<router-link to="/">Go to Home</router-link>
<router-link to="/about">Go to About</router-link>
</p>
<router-view></router-view>
</div>
<script src="https://unpkg.com/vue@3"></script>
<script src="https://unpkg.com/vue-router@4"></script>
<!-- include office.js make vue-router not working -->
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script>
const Home = { template: '<div>Home</div>' }
const About = { template: '<div>About</div>' }
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About },
]
})
const app = Vue.createApp({})
app.use(router)
app.mount('#app')
</script>
</body>
</html>我现在能在网上找到的是一个解决办法
在导入vue路由器并插入之前插入以下内容。
delete window.history.pushState; // workaround to make sure vue router doesn't try using pushState
delete window.history.replaceState; // workaround to make sure vue router doesn't try using replaceState发布于 2022-09-01 16:04:52
我发现使用VueRouter.createMemoryHistory()可以解决这个问题。
https://stackoverflow.com/questions/73023923
复制相似问题