Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

javascript - VueJS无法编译和运行未格式化为VueJS样式的JavaScript(VueJS will not compile and run JavaScript not formated like VueJS style)

This is my javascript.js file

(这是我的javascript.js文件)

function test_script(div) {
    // If I do not use eslint-disable/enable then I get an error from Vue
    /* eslint-disable no-console */
    console.log(div);
    /* eslint-enable no-console */
}

that is it.

(这就对了。)

A simple javascript.js file to test if it can take a parameter and print it.

(一个简单的javascript.js文件,用于测试它是否可以带参数并进行打印。)

To be clear: the issue (error about using the keyword function and declaring a method(function) outside methods: {} ) still arrises with, for example, the following code since it is not in VueJS format.

(需要明确的是:问题(关于使用关键字function并在methods: {}之外声明方法(函数)的错误)仍然存在,例如以下代码,因为它不是VueJS格式。)

This error arrises both in the App.vue and index.html

(此错误同时出现在App.vue和index.html中)

function test() {
    /* eslint-disable no-console */
    console.log("hello, world!");
    /* eslint-enable no-console */
}

Whenever I try to implement the JS code in the following way it the VueJS application is invisible for the user and is notwhere to be found in the inspection delevoper tool of chrome and FF for the user (again, both in App.vue, any other .vue file and index.html

(每当我尝试以以下方式实现JS代码时,VueJS应用程序对于用户都是不可见的,并且在用户的chrome和FF的检查delevoper工具中找不到(再次在App.vue中,以及其他任何版本中) .vue文件和index.html)

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

the javascript.js is in the same folder, and I have copies of it in all directories just in case anyone would argue that it is an issue of finding the script.

(javascript.js位于同一个文件夹中,我在所有目录中都有它的副本,以防万一有人认为这是查找脚本的问题。)

Also the script inside the file is what causes the error so the file is definity found both with a copy of the script in each folder and with the script only in the correct folder.

(此外,文件内的脚本是导致错误的原因,因此,在每个文件夹中都有一个脚本副本,并且仅在正确的文件夹中有脚本,因此文件是不完整的。)

The VueJS dissapears when I copy and paste the content inside the script tags like this

(当我将内容复制并粘贴到脚本标签中时,VueJS消失了)

<script>
function test_script(div) {
    // If I do not use eslint-disable/enable then I get an error from Vue
    /* eslint-disable no-console */
    console.log(div);
    /* eslint-enable no-console */
}
</script>

and the VueJS application gets replaced and not loaded in any way to the user when I add the folllowing script anywhere in the code (before the original tags or after or in the beginning of the file (still App.vue or index.html), etc.

(当我在代码中的任何位置(原始标签之前或之后,文件的开头或之后(仍为App.vue或index.html))添加以下脚本时,VueJS应用程序将被替换并且不会以任何方式加载给用户等等)

<script>
/* eslint-disable no-console */
console.log();
/* eslint-enable no-console */
</script>

Adding the script as a plugin does not work, that only results in a crach or freeze of the computer followed up with infinite attemps to build the VueJS project.

(将脚本添加为插件无法正常工作,只会导致计算机崩溃或死机,随后会无限次尝试构建VueJS项目。)

Summary: Adding "regular" JS code in my VueJS project in any .vue or .html file using script tags in any way fails miserably.

(简介:以任何方式使用脚本标记在我的VueJS项目的任何.vue或.html文件中添加“常规” JS代码都失败了。)

How does one include JS code not in the format of VueJS

(如何包含非VueJS格式的JS代码)

Edit: folder structure

(编辑: 文件夹结构)

  ask by RealAnwersOnly translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...