所以,我只是發現了它與路由器的歷史模式是做的,如果我從router.js刪除'mode': 'history',
一切再次工作!離開這裏,如果別人有同樣的問題,或者如果有人能夠提供解釋......
原始
我不能使用VUE V2與VUE路由器和科爾多瓦(即建設以cordova/www
並從index.html文件中獲得了cordova的工作)。我曾經可以使用vue和vue-router v1。我也能夠使用vue v2,但不使用vue-router。
要明確,該應用程序工作時使用npm run dev
只是不打開時建立index.html
。
我有一種感覺,這與路由器尋找路徑/
但看到index.html
?
Here's a repo where you can reproduce the problem.
下面是一些相關的代碼:
main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router/router.js'
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
// replace the content of <div id="app"></div> with App
render: h => h(App)
})
app.vue
<template>
<div id="app">
<img src="./assets/logo.png">
<router-view></router-view>
</div>
</template>
<script>
import Hello from './components/Hello'
export default {
name: 'app',
components: {
Hello
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
個/router/router.js
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Hello from '../components/Hello'
export default new Router({
'mode': 'history',
scrollBehavior:() => ({ y: 0 }),
'routes': [
{
'path': '/',
'component': Hello
}
]
})
配置/ index.js
// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../../cordova/www/index.html'),
assetsRoot: path.resolve(__dirname, '../../cordova/www'),
assetsSubDirectory: 'static',
assetsPublicPath: '',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css']
},
dev: {
env: require('./dev.env'),
port: 8080,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}
嘗試在'config/index.js'的構建塊中設置'assetsPublicPath:'./''。我有使用vue-router工作的Vue2 Cordova應用程序,所以它絕對有可能 – toast38coza