【发布时间】:2021-11-28 17:05:56
【问题描述】:
有谁知道当我在 nuxt.config.js 中将@turf/helpers 添加到我的buildModules 时,为什么会得到Module should export a function: @turf/helpers?
nuxt.config.js
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
'@turf/helpers'
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
],
我是否将模块添加到错误的数组中?
仅供参考:该模块存在于我的 package.json / 依赖项中。至此,安装成功。
// import { point } from '@turf/helpers' 返回未定义的组件
<script>
import { defineComponent } from '@vue/composition-api';
import mapboxgl from 'mapbox-gl';
import { point } from '@turf/helpers'
export default defineComponent({
data () {
return {
geojson: {
'type': 'FeatureCollection',
'features': []
},
map: null,
}
},
mounted() {
this.initMapBox();
},
methods: {
// Initialize MapBox map
initMapBox: function() {
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxleGFuZHJ1YW5hIiwiYSI6ImNrZTl3NzJ3bzIxNG4yc2w2aG03dHNkMDUifQ.xaSxrVMLZtfGAlWoGvB1PQ';
this.map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/alexandruana/cksxeq0637zjy17tcvd4h919d',
center: [22.253, 45.419],
zoom: 4
});
this.map.on('load', () => {
console.log('Map loaded.')
let point = point([22.253, 45.419]);
console.log(point)
this.map.addSource('points', {
type: 'geojson',
data: this.geojson
});
this.map.addLayer({
id: 'points',
type: 'circle',
source: 'points',
paint: {
'circle-radius': 8,
'circle-color': '#00a9e2'
},
filter: ['in', '$type', 'Point']
});
});
},
}
})
【问题讨论】:
-
您在哪里看到这是一个 Nuxt 模块?这是一些常规的 JS 代码。
-
我在他们的文档中看到他们将此包称为模块。您是否建议它根本不必在 nuxt.config.js 文件中注册?
-
你能链接这部分文档吗?
-
不确定它是否是原始文档,但我在这里阅读:npmjs.com/package/@turf/turf。我认为我不需要在 nuxt.config 中包含任何内容,但是由于某种原因我没有设法使用
@turf/helpers的point功能,并且当我尝试运行上面的代码时,我不断收到提示Uncaught TypeError: point is not a function(现在更新)。我的猜测是我没有正确导入 { point }?感谢您一直以来的支持!