代码之家  ›  专栏  ›  技术社区  ›  RGriffiths

在nuxt项目中使用gmap-vue

  •  0
  • RGriffiths  · 技术社区  · 3 年前

    我想利用 gmap-vue 在nuxt项目中。我很困惑

    在main.js或Nuxt插件中:

    因为我没有main.js,也没有任何插件。

    然而,我尝试创建了一个名为gmap.js的新插件文件:

    import Vue from 'vue'
    import * as GmapVue from 'gmap-vue'
    
    Vue.use(GmapVue, {
        load: {
            key: process.env.gMapKey,
        },
        installComponents: true
    })
    

    然后添加到nuxtcongif.js中

    plugins: [
        '~/plugins/gmap.js'
    ],
    

    但我在浏览器中遇到了错误:

    SyntaxError Unexpected token '<'
    

    在gmap.js中,它不会重新分配模块:

    enter image description here

    有什么建议可以让它发挥作用吗?

    0 回复  |  直到 3 年前
        1
  •  2
  •   nontechguy    3 年前

    更改此行

    import * as GmapVue from 'gmap-vue';
    

    对此(请参阅gmap-vue文档 Nuxt.js config )

    import * as GmapVue from '~/node_modules/gmap-vue';
    
        2
  •  1
  •   Vadim Gremyachev    3 年前

    For Nuxt.js 应用程序将以下选项添加到您的 nuxt.config.js's build.extend() :

    build: {
        transpile: [/^gmap-vue($|\/)/]
    }
    

    类似 vue2-google-maps Nuxt.js config 哪一个 gmap-vue 是的叉子。