首页 > 解决方案 > 如何使我的自定义 CSS 和 Javascript 文件在我的 vuejs 应用程序中工作

问题描述

正在开发一个项目,在我的 vuejs 应用程序中,我注意到如果我应该导航到带有参数的路由,我的 index.html 中的 CSS 和我的 javascript 将不包括在内,它会在控制台中给我这个错误

Uncaught SyntaxError: Unexpected token <

这是我的路由器代码

import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";

Vue.use(Router);

export default new Router({
  mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: '/profile/:id/',
      name: 'Profile',
      secure: true,
      component: () =>
      import(/* webpackChunkName: "Profile" */ "./components/slots/Users/profile.vue")
    },
    {
      path: '*',
      component: () =>
      import(/* webpackChunkName: "404" */ "./components/slots/404.vue")
    }    
  ]
});

如果我应该去个人资料路线,我的 css 和 javascript 工作但如果我应该将其更改为

{
  path: '/profile/',
  name: 'Profile',
  secure: true,
  component: () =>
  import(/* webpackChunkName: "Profile" */ "./components/slots/Users/profile.vue")
},

我的 css 和我的 javascript 将重新开始工作

这是我的 index.html 代码

<!DOCTYPE HTML>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>CyberSec</title>
    <link rel="shortcut icon" href="assets/ico/favicon.ico">
    <link rel="stylesheet" type="text/css" href="assets/css/theme.css">
   <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <noscript>
      <strong>We're sorry but client doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div> 
  </body>
  <script type="text/javascript" src="assets/plugins/jquery/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="assets/js/theme.js"></script>
</html>

请问我该如何解决这个问题或者我做错了什么

标签: vue.jsvuejs2vue-routerapollo-client

解决方案


推荐阅读