未找到 CSS 和 JS 的 Vue dist 路径

2024-04-17

我在构建后渲染 VueJS 应用程序时遇到问题。当我查看构建文件夹并检查路径时,我的资产、css 和 javascript 的路径开头有一个正斜杠。这使得我的 css、资源和 javascript 无法找到。我想知道在运行构建脚本之前如何避免这个问题。谢谢。这是我的代码:

App.vue

<template>
  <div id="app">
    <BaseTimer />
    <!-- <PomodoroTimer /> -->
  </div>
</template>

<script>
import BaseTimer from "./components/BaseTimer";
// import PomodoroTimer from "./components/PomodoroTimer";

export default {
  name: "App",

  components: {
    BaseTimer
    // PomodoroTimer
  }
};
</script>

<style>
body {
  background-color: #fff;
}

#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;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
}
</style>

BaseTimer.vue(在组件文件夹内 - 在 src 文件夹内)

<template>
  <div class="base-timer">
    <svg class="base-timer__svg" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
      <g class="base-timer__circle">
        <circle class="base-timer__path-elapsed" cx="50" cy="50" r="45" />
        <path
          :stroke-dasharray="circleDasharray"
          class="base-timer__path-remaining"
          :class="remainingPathColor"
          d="
            M 50, 50
            m -45, 0
            a 45,45 0 1,0 90,0
            a 45,45 0 1,0 -90,0
          "
        />
      </g>
    </svg>
    <span class="base-timer__label">{{ formattedTimeLeft }}</span>
    <br />
    <select name="timer-setter" id="timer-setter" @change="selectedTime($event)">
      <option value selected disabled>---Select a Time---</option>
      <option v-for="second in seconds" :value="second.value" v-bind:key="second.id">{{second.text}}</option>
    </select>
    <button id="start" class="button is-dark is-large" @click="startTimer">GO</button>
    <div class="pause-or-kill">
      <!--     Pause Timer -->
      <button id="stop" class="button is-dark is-large" @click="pauseTimer">Pause</button>
      <!--     Restart Timer -->
      <button id="reset" class="button is-dark is-large" @click="restartTimer">Restart</button>
      <button id="kill" class="button" @click="kill">Reset</button>
    </div>
  </div>
</template>

<script>
let audio = new Audio(require("/assets/audio/ding.mp3"));

const FULL_DASH_ARRAY = 283;
const WARNING_THRESHOLD = 10;
const ALERT_THRESHOLD = 5;

const COLOR_CODES = {
  info: {
    color: "green"
  },
  warning: {
    color: "orange",
    threshold: WARNING_THRESHOLD
  },
  alert: {
    color: "red",
    threshold: ALERT_THRESHOLD
  }
};

let TIME_LIMIT = null;

export default {
  data() {
    return {
      timePassed: 0,
      timerInterval: null,
      seconds: [
        { id: 0, value: null, text: "--- Select a Time ---" },
        { id: 1, value: 20, text: "20 Seconds" },
        { id: 2, value: 30, text: "30 Seconds" },
        { id: 3, value: 60, text: "1 Minute" },
        { id: 4, value: 120, text: "2 Minutes" },
        { id: 5, value: 300, text: "5 Minutes" },
        { id: 6, value: 600, text: "10 Minutes" },
        { id: 7, value: 900, text: "15 Minutes" },
        { id: 8, value: 1800, text: "30 Minutes" },
        { id: 9, value: 3600, text: "1 Hour" }
      ]
    };
  },

  computed: {
    circleDasharray() {
      return `${(this.timeFraction * FULL_DASH_ARRAY).toFixed(0)} 283`;
    },

    formattedTimeLeft() {
      const timeLeft = this.timeLeft;
      const minutes = Math.floor(timeLeft / 60);
      let seconds = timeLeft % 60;

      if (seconds < 10) {
        seconds = `0${seconds}`;
      }

      return `${minutes}:${seconds}`;
    },

    timeLeft() {
      return TIME_LIMIT - this.timePassed;
    },

    timeFraction() {
      const rawTimeFraction = this.timeLeft / TIME_LIMIT;
      return rawTimeFraction - (1 / TIME_LIMIT) * (1 - rawTimeFraction);
    },

    remainingPathColor() {
      const { alert, warning, info } = COLOR_CODES;

      if (this.timeLeft <= alert.threshold) {
        return alert.color;
      } else if (this.timeLeft <= warning.threshold) {
        return warning.color;
      } else {
        return info.color;
      }
    }
  },

  watch: {
    timeLeft(newValue) {
      if (newValue === 0) {
        this.onTimesUp();
      }
    }
  },

  // startTimer() {
  //   this.startTimer();
  // },

  methods: {
    onTimesUp() {
      clearInterval(this.timerInterval);
      audio.play();
      setTimeout(function() {
        location.reload();
      }, 2000);
    },
    startTimer() {
      this.timerInterval = setInterval(() => (this.timePassed += 1), 1000);
    },
    restartTimer() {
      clearInterval(this.timerInterval);
      this.timerInterval = setInterval(() => (this.timePassed += 1), 1000);
    },
    pauseTimer() {
      clearInterval(this.timerInterval);
    },
    kill() {
      clearInterval(this.timerInterval);
      location.reload();
    },
    selectedTime(event) {
      console.log(event.target.value);
      TIME_LIMIT = event.target.value;
    }
  }
};
</script>

<style scoped lang="scss">
.base-timer {
  position: relative;
  width: 300px;
  height: 300px;

  &__svg {
    transform: scaleX(-1);
  }

  &__circle {
    fill: none;
    stroke: none;
  }

  &__path-elapsed {
    stroke-width: 7px;
    stroke: grey;
  }

  &__path-remaining {
    stroke-width: 7px;
    stroke-linecap: round;
    transform: rotate(90deg);
    transform-origin: center;
    transition: 1s linear all;
    fill-rule: nonzero;
    stroke: currentColor;

    &.green {
      color: rgb(65, 184, 131);
    }

    &.orange {
      color: orange;
    }

    &.red {
      color: red;
    }
  }

  &__label {
    position: absolute;
    width: 300px;
    height: 300px;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
  }
}

select {
  margin-top: 30px;
  margin-right: 15px;
  padding: 15px;
  border-radius: 8px;
  background-color: rgb(65, 184, 131);
  color: #fff;
  font-size: 18px;
  -webkit-box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
  box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
}

button {
  padding: 15px;
  font-size: 18px;
  background-color: rgb(65, 184, 131);
  border-radius: 8px;
  color: #fff;
  -webkit-box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
  -moz-box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
  box-shadow: 10px 10px 20px -8px rgba(0, 0, 0, 0.75);
  outline: none;
}
.pause-or-kill {
  margin-top: 20px;
}
</style>

src 文件夹中的index.html

<!DOCTYPE html>
<html>

<head>
    <title>Vue Parcel</title>
    <meta charset="utf-8">
</head>

<body>
    <div id="app"></div>
    <script src="index.js"></script>
</body>

</html>

src 文件夹内的index.js

import Vue from "vue";
import App from "./App.vue";

Vue.config.productionTip = false;


new Vue({
  render: h => h(App)
}).$mount("#app"); 

默认情况下,该路径指向服务器根目录。这意味着/如果在 Apache/node 等 Web 服务器上静态提供文件,甚至直接在c:\例如,如果在 Windows 上双击。

假设您使用的是 Vue CLI,您可以通过编辑或创建来配置此位置vue.config.js在你的项目根目录中使用publicPath:

module.exports = {
  publicPath: process.env.NODE_ENV === 'production'
    ? '/your/path/to/dist/'
    : '/'
}

这让 Vue 为开发服务器提供服务/正如预期的那样,并在生产中使用其他路径。 CLI 自动设置process.env.NODE_ENV如果你想知道。修改此文件后不要忘记重建。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未找到 CSS 和 JS 的 Vue dist 路径 的相关文章

随机推荐

  • 使用所需的优化标志重新构建 Tensorflow

    预先感谢您的考虑 我刚刚使用以下命令安装了tensorflow 在已安装Ubuntu 16 04和CUDA 8 0的新机器上 程序 http www nvidia com object gpu accelerated application
  • 溢出-y滚动即使没有溢出也总是显示

    我正在做 与内容分开滚动 JQuery Mobile 面板 我做了什么 https forum jquery com topic scroll inside panel 我应用这个 css 来实现我所做的事情 但问题是 Overflow y
  • Celery + SQLAlchemy:DatabaseError:(DatabaseError)SSL错误:解密失败或坏记录mac

    当在启用 SSL 的 postgresql 数据库上使用 celery 和多个工作线程时 有时会触发标题错误 我使用 Flask SQLAlchemy 配置 正如这里提到的 https github com celery celery is
  • 防止 PHP 中的目录遍历但允许路径

    我有一个基本路径 whatever foo and GET path 应该是相对的 但是 如何在不允许目录遍历的情况下完成此操作 读取目录 eg 无法正确过滤 好吧 一种选择是比较真实路径 basepath foo bar baz real
  • Azure 文件存储内容类型始终为 application/octet-stream

    目前 当我使用以下内容构建 URL 时 我遇到了 Azure 文件存储问题共享访问签名 SAS 令牌 https learn microsoft com en us azure storage common storage dotnet s
  • 如何使用Python在多进程中运行pycuda

    我有一个可以在单个进程中运行的 pycuda 代码 python的多进程可以支持在多个子进程中运行这段代码吗 如果我尝试 我会发现我犯了一个错误 我做错了吗 我尝试用python的进程实现一个简单的多进程 发现会出错 import pycu
  • Java 反射调用原始类型的构造函数

    我的测试框架中有一个方法 可以根据传入的参数创建类的实例 public void test Object constructorArgs throws Exception Constructor
  • 如何在 Automapper 中使用数据集?

    我目前使用数据读取器作为源 但我想改用数据集 datareader AutoMapper Mapper CreateMap
  • 确定事务中无法执行的T-SQL/DDL

    有多种语句和系统过程无法在事务中执行 并出现错误消息 不允许 例如 create database 或 无法执行 例如 exec sp addrole 是否存在一条或一组规则来指示事务中是否不允许给定的过程 语句 有其列表吗 不是 Micr
  • 使用 AWS CodeBuild 构建 Windows 容器

    我正在开始使用 AWS 的 CI CD 功能 到目前为止 我已经基于 microsoft windowsservercore 映像在 Windows Server 2016 本地创建了 docker 映像 并将其手动推送到 ECR 亚马逊容
  • 内联块 div 中的文本将其向下推[重复]

    这个问题在这里已经有答案了 今天早上我发现了一个奇怪的 CSS 问题 我希望 CSS 专家能帮助我 在这个演示 http jsfiddle net 7HBCe 为什么红色 div 中的文本将其向下推 我预计这两个 div 会彼此相邻 谢谢
  • 删除Elasticsearch中类型的文档

    我想使用 HTTP REST api 删除 Elasticsearch 中某一类型中索引的所有文档 但我不想删除该类型的映射 如何在 URL 中构建查询来执行此操作 执行命令前 索引 映射状态 截图取自elasticsearch头插件网络界
  • 你能帮助解释我的 svn diff 输出吗?

    我正在使用 SVN DIFF 比较两个文件夹 一个在分支中 一个在主干中 目的是确定更改列表 然后我对分支中的文件进行了一些更改 但输出显示我已经在主干中修改了它们 为什么会出现这种情况 有没有更好的命令来获取我正在寻找的结果 我现在使用的
  • 具有 EasyIn 动画,然后按顺序缩放动画,因为缩放动画会永远重复

    我想要在 onAppear 上为文本信息和 SF 符号添加一个 escapeIn moveUp 动画 此后 我只希望 SF 符号永远按比例放大和缩小 目前 我已经设法永远缩小规模 但是当我设法链接时 easeIn moveUp 动画也会永远
  • Julia 似乎没有使用字符串来执行插值

    官方文档指出 连接和字符串插值调用string 将对象转换为字符串形式 然而 以下最小工作示例似乎证明了其他情况 type MyType x Int end import Base string Base string m MyType w
  • ... 不支持谷歌地图 Javascript API。使用其他浏览器

    我正在使用两个不同的第三方程序 不同的公司 它们显然使用 Google Maps Javascript API 当他们加载地图时 会显示世界地图 但会显示一条错误消息 Der von Ihnen verwendete Browser wir
  • 如何用动画消除一堆模态视图控制器而不在屏幕上闪烁顶部和底部之间任何呈现的 VC?

    更新 通过下面的 屏幕截图 方法修复 这可行 但是有更优雅的方法吗 我将如何消除一堆带有动画的模态视图控制器 而不在屏幕上闪烁顶部和底部之间任何呈现的 VC 尝试用动画来做到这一点是行不通的 请参阅下面的代码和描述我的问题的内嵌注释 您可以
  • 当客户端不正常退出时,如何检测服务器上 Python aiohttp Web 套接字的关闭

    我有一个简单的命令和控制服务器server py 完全不安全 不要使用 被动客户端update client py和另一个可以发送命令的客户端update commander py 有一个 http 端点http 0 0 0 0 8080
  • NAT 穿越和 IPv6

    我很好奇一旦 IPv6 的部署和使用增加 NAT 和 NAT 穿越机制的用处 我们有很多 NAT 遍历机制 包括专有的 主要用于某种住宅或企业 NAT 背后的 IPv4 设备 客户端 鉴于 NAT 的出现是因为 IPv4 缺乏可用地址 那么
  • 未找到 CSS 和 JS 的 Vue dist 路径

    我在构建后渲染 VueJS 应用程序时遇到问题 当我查看构建文件夹并检查路径时 我的资产 css 和 javascript 的路径开头有一个正斜杠 这使得我的 css 资源和 javascript 无法找到 我想知道在运行构建脚本之前如何避