使用的是Vue-cli创建的项目,我写了一个js文件,里面有一些会用到的函数。但这里突然就不能用了,找不出什么毛病啊。
import ol from 'openlayers'
const isLayerExist = (id) => {
let isExist = false
window.map.getLayers().forEach(function (layer) {
if (layer.get('id') === id) {
isExist = true
}
})
return isExist
}
const toggleLayerVisible = (id, show) => {
window.map.getLayers().forEach(function (layer) {
if (layer.get('id') === id) {
layer.setVisible(show)
}
})
}
const generateLayer = ({type, url, id}) => {
switch (type) {
case 'ImageWMS':
createImageWMS({url, id})
break
default:
break
}
}
const createImageWMS = (url, id, opacity = 0.9) => {
let tiled = new ol.layer.Image({
opacity: opacity,
source: new ol.source.ImageWMS({
url: url,
wrapX: false
}),
visible: true,
id: id
})
window.map.addLayer(tiled)
}
exports.isLayerExist = isLayerExist
exports.toggleLayerVisible = toggleLayerVisible
exports.generateLayer = generateLayer
在组件里面是这样引用的
import maputils from '../utils/maputils'
vue界面就出不来了,引用其他文件是可以的,到这儿就行了,程序界面直接无法访问。命令行里面也没有报错,而浏览器里面说是
Uncaught ReferenceError: exports is not defined