编辑
所以我刚刚发现它与路由器处于历史模式有关,如果我'mode': 'history',
从 router.js 中删除,一切都会再次运行!如果其他人有同样的问题,或者如果有人可以提供解释,请离开这里......
原来的
我无法将 vue v2 与 vue-router 和 cordova 一起使用(即构建到cordova/www
index.html 文件并让 cordova 工作)。我曾经能够使用 vue 和 vue-router v1。我也可以使用 vue v2,但不使用 vue-router。
需要明确的是,该应用程序在使用npm run dev
时有效,而在打开内置的index.html
.
我有一种感觉,这与路由器寻找/
但看到的路径有关index.html
?
下面是一些相关代码:
主.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),
});
应用程序.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>
/路由器/路由器.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,
}
}