【问题标题】:Error importing script in vue file in Vue 3在 Vue 3 的 vue 文件中导入脚本时出错
【发布时间】:2021-07-04 18:26:10
【问题描述】:

我在 Vue 3 中使用 laravel-mix,但出现以下错误:

ERROR in ./resources/js/components/App.vue 2:0-54
Module not found: Error: Can't resolve './App.js/?vue&type=script&lang=js' in './resources/js/components'

组件/App.vue

<template>
    <div id="app">
        <h1>Hello world</h1>
    </div>
</template>
<script src="./App.js/"></script>

组件/App.js

export default {
    name: "App",
};

在我之前使用 Vue 2 和 Laravel 7 的项目中,我没有遇到这些错误。现在我正在使用 Vue 3 和 Laravel 8,但不知道如何修复它。我已经安装了vue-loader 和vue-template-compiler,所以我想它应该可以工作。

Vue 3 是否允许从单独的 js 文件中导入脚本?在 Vue 2 中这是可能的(我喜欢将 HTML 与 JS 分开,因为我的编辑器存在一些问题,也为了更好的组织。)

【问题讨论】:

  • App.js 末尾的额外正斜杠应该在那里吗?看起来很可疑&lt;script src="./App.js/"&gt;&lt;/script&gt;
  • @steve16351 你是对的!感谢您指出了这一点;我自己没有想到这一点。如果您将其发布为答案,我会接受。

标签: laravel vuejs3 laravel-mix


【解决方案1】:

这与 Vue3 无关,只是你在文件后添加了斜线,所以它被理解为一个目录。

<script src="./App.js/"></script>

到

<script src="./App.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    • 2021-07-08
    • 2022-01-09
    • 2022-10-23
    • 2019-05-26
    • 2020-06-14
    • 2019-04-13
    相关资源
    最近更新 更多