[英]Including my own js and css file in a vue cli3 project
I have a couple of js and css files which were custom built and i want to include that into my vue cli3 project. 我有几个自定义构建的js和css文件,我想将它包含在我的vue cli3项目中。 Is there any way to import those files into my project ?
有没有办法将这些文件导入我的项目?
For custom js files, write all your logic in a object and export it at the end of the file : 对于自定义js文件,将所有逻辑写入对象并将其导出到文件末尾:
const customJs = {
/* custom javascript here */
}
export default customJs;
and then import it where you need it as : 然后将其导入到您需要的位置:
import * as customJs from '../path/to/file.js'
For custom css files, you can use @import
between the style
tags like this: 对于自定义css文件,您可以在
style
标记之间使用@import
,如下所示:
@import './../node_modules/foo/bar.css';
You can use a pre-processor when creating the project with vue-cli. 使用vue-cli创建项目时,可以使用预处理器。
See: Working with CSS 请参阅:使用CSS
Or if you don't need a pre-processor and you are using CSS modules you can go for this route 或者,如果您不需要预处理器并且使用CSS模块,则可以使用此路由
As for JavaScript it's pretty straight forward if you are on ES2016/ES6 just use the syntax 至于JavaScript,如果您使用ES2016 / ES6只是使用语法,那么它非常简单
import tool from 'toolmodulename';
Try this in main.js 在main.js中试试这个
import "path-your-css/your-css.css"; 导入“path-your-css / your-css.css”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.