外部托管时VueJS无法正常工作

时间:2017-03-05 19:46:58

标签: javascript html typescript vue.js

我在VueJS中开发了一个小应用程序,在使用本地网络服务器进行开发时似乎工作正常。但是当我将它部署到Github页面时,它根本不会加载。 我也尝试在我自己的服务器上部署它,这也不起作用。

Javascript代码执行正常,但不知何故Vue代码没有。

Link to the website where I've deployed it

Github repository

2 个答案:

答案 0 :(得分:2)

如果您使用默认的vuejs / vue-router设置并且要发布到子文件夹,则在http://example.com/folder/的情况下,vue-router可以选择修改base。 / p>

import Vue from 'vue'

import Router from 'vue-router'

import Home from '@/components/Home'

Vue.use(Router)

const routes = [
 { path: '/', name: 'Home', component: Home }
]

export default new Router({
 routes,
 mode: 'history',
 base: '/folder'
})

答案 1 :(得分:1)

我发现了问题,它与我在特定设置上的路由有关。

当Vue的路由器在服务器上定义了路由时,它将使用已经给出的路由路径。 我的问题是使用Vue路由器将应用程序部署在一个文件夹中。 因此,当您执行应用时,当前路径将指向http://example.com/folder/,而您的路线在我的情况下指向http://example.com/

如果由于某种原因另一个路由失败,我通过定义备用路由来解决问题。

routes: [
    { path: '/', name: "CollectionMarker", component: CollectionMarker },
    { path: '/cars', name: "CarMarker", component: CarsComponent },
    // This is the path that you need to include, it will redirect when no route has been found
    { path: "*", redirect: "/" }
]
相关问题