Vue encapsulates js and introduces external js files
Package js
Create a new AA.js file in the src directory first
export default {
AA: function (maps) {
return maps + 1
}
}
Introduced in the main.js file
import AA from '@/AA.js'
Vue.prototype.AA = AA
In this way, you can
test.vue in the component you want to use
console.log(this.AA.AA(1));
Or
create a new BB.js file
export function AA(){
return 1
}
export function BB(){
return 2
}
Introduced in the component
import {
AA , BB } from './BB.js'
console.log(AA)
console.log(BB)
Introduce external js
Introduce mapboxgl, place the downloaded Cesium folder under public, and include the file path in index.html
<script src='./mapboxgl/mapboxgl.js'></script>
Write in vue.config.js
module.exports = {
configureWebpack: {
externals: {
'mapboxgl': 'mapboxgl',
}
}
}
Just introduce
test.vue where needed
import mapboxgl from 'mapboxgl' //或者
const Cesium = require('mapboxgl')