对不起,如果我的问题愚蠢,但我是Vue的新手:( 我遇到某种悖论,肯定是我做错了什么。我有一个.js文件,在jQuery中有一些功能。我想将其导入我的vue应用。所以我在App.vue中使用:
import { fabric } from 'fabric'
import '../src/main-copy.js'
在第一行中,我导入要使用画布的结构,在第二行中,我尝试导入我的文件,但出现错误:
Failed to compile.
./src/main-copy.js
Module Error (from ./node_modules/eslint-loader/index.js):
C:\path\vue-test\src\main-copy.js
8:1 error '$' is not defined no-undef
9:35 error 'fabric' is not defined no-undef
120:11 error '$' is not defined no-undef
162:12 error 'tf' is not defined no-undef
164:22 error 'tf' is not defined no-undef
167:25 error 'tf' is not defined no-undef
170:24 error 'tf' is not defined no-undef
171:28 error 'tf' is not defined no-undef
所以我用npm安装了jquery和tensorflow,并将其导入到App.vue:
import { fabric } from 'fabric'
import { jquery } from 'jquery'
import { tensorflow } from 'tensorflow'
import '../src/main-copy.js'
但是当我添加此导入时,出现新错误:
Failed to compile.
./src/App.vue
Module Error (from ./node_modules/eslint-loader/index.js):
C:\path\vue-test\src\App.vue
11:10 error 'jquery' is defined but never used no-unused-vars
12:10 error 'tensorflow' is defined but never used no-unused-vars
我什至尝试添加简单的
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
到index.html,但没有结果。 我做错了什么?请帮忙。
main-copy.js的一部分:
var model;
var canvas;
var classNames = [];
var coords = [];
var mousePressed = false;
$(function() {
canvas = window._canvas = new fabric.Canvas('canvas');
canvas.backgroundColor = '#ffffff';
canvas.isDrawingMode = 0;
canvas.freeDrawingBrush.color = "black";
canvas.freeDrawingBrush.width = 10;
canvas.renderAll();
canvas.on('mouse:up', function(e) {
getFrame();
mousePressed = false;
});
canvas.on('mouse:down', function(e) {
mousePressed = true;
});
canvas.on('mouse:move', function(e) {
recordCoor(e);
});
});