如何在Vue中包含本地脚本文件 [英] How to include local script files in Vue

查看:63
本文介绍了如何在Vue中包含本地脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 VS 代码编写的基本项目,并且是一项非常简单的任务.我想以正确的方式在我的项目中包含一个旧的 javascript 文件,以便在浏览器中加载它.
该文件应位于 src\assets\scripts\oldLegacyScript.js

我尝试了这个hack:

如果我遵循此解决方案:

那么我该如何克服在我的 Vue 项目中导入一个简单的 javascript 文件的简单任务?

解决方案

像这样导入

I have a basic project in VS code, and quite a simple task. I want to include an old javascript file in my project the correct way, so it gets loaded in the browser.
The file should be located in src\assets\scripts\oldLegacyScript.js

I tried this hack: How to add external JS scripts to VueJS Components which injects a <source> tag in the document on runtime. This only works if I put the .js file in the generated public folder in where the compiled files will be. If the file is not in the public folder the browser tries to download the index.html file, which I cannot understand:

If i follow this solution: Importing javascript file for use within vue component I get syntax errors on the import statement:

So how the heck do I overcome this simple task of importing a simple javascript file in my Vue project?

解决方案

Import like this

<script>
import * as myKey from '.src/..';

export default {

}
</script>

这篇关于如何在Vue中包含本地脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆