Ada*_*dam 26 cordova vue.js vue-router
编辑
所以我发现它与路由器处于历史模式有关,如果我'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
吗?
以下是一些相关代码:
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)
})
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
/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
}
]
})
Run Code Online (Sandbox Code Playgroud)
配置/ 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
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
您可能正在从磁盘加载文件("file://"),并且从"file://"加载文件时浏览器历史记录API pushstate不起作用.当您从路由器中删除"mode:history"时它会起作用,因为它默认使用哈希值.
归档时间: |
|
查看次数: |
4112 次 |
最近记录: |