First use the src relative path to import
Notice:
js files should be placed under the public file and not under the assets static resource file
, otherwise an error may be reported
GET http://192.168.0.113:8080/src/assets/js/websockets.js net::ERR_ABORTED 500 (Internal Server Error)
The correct use is as follows: eg
// html中引入 方式一
<script src="./websockets.js"></script>
// 方式二
<script src="<%= BASE_URL %>websockets.js"></script>
<%=%> is ejs template syntax
ejs template syntax is to be able to use js variables in html files
For versions before Vue CLI 3.3, BASE_URL corresponds to the baseURl field in vue.config.js. For
versions after vue CLI 3.3 (including 3.3), it corresponds to publicPath
The / in publicPath represents the path of the static resource after packaging, that is to say, it represents the path of the dist folder after packaging
Want to modify BASE_URL,
version before Vue CLI 3.3, configuration: baseURl: '/static'
Version after Vue CLI 3.3 (including 3.3), configuration: publicPath: '/static'
// 还可以通过环境判断
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/static/'
: '/'
}