yandex-maps-unofficial / vue-yandex-map

Yandex Maps Component for VueJS
MIT License
359 stars 103 forks source link

Не работает НЕ глобальная установка компонета #2

Closed Gemorroj closed 7 years ago

Gemorroj commented 7 years ago

firefox js error:

[Vue warn]: Error in beforeCreate hook: "TypeError: this.$ymapEventBus is undefined"

chrome js error:

[Vue warn]: Error in beforeCreate hook: "TypeError: Cannot read property 'scriptIsNotAttached' of undefined"


app.js

import Vue from 'vue';
import VueRouter from 'vue-router';

import AppLayout from './AppLayout.vue';
import Home from './pages/Home.vue';
import Contact from './pages/Contact.vue';

Vue.use(VueRouter);

const router = new VueRouter({
    mode: 'history',
    base: __dirname,
    routes: [
        { path: '/', name: 'home', component: Home },
        { path: '/contact', name: 'contact', component: Contact }
    ]
});

const app = new Vue({
    router,
    render: function (h) {
        return h(AppLayout);
    }
}).$mount('#app');

Contact.vue

<template>
    <main>
        <p>Contact page</p>

        <yandex-map :coords="[54.62896654088406, 39.731893822753904]"
                    zoom="10"
                    style="width: 600px; height: 600px;">
        </yandex-map>
    </main>
</template>

<script>
    import YandexMap from 'vue-yandex-maps';
    export default {
        components: {
            YandexMap
        }
    }
</script>
PNKBizz commented 7 years ago

Спасибо! Буду фиксить

votetake commented 7 years ago

Актуально

PNKBizz commented 7 years ago

Пофиксил в версии 0.1.2. Правда пришлось пожертвовать cdn, не смог совместить. Но я думаю cdn все равно никому не нужен =) Проверяйте и пишите, буду реагировать быстрее. На проекте была запара месяц...

Gemorroj commented 7 years ago

Заработал только в таком виде

<template>
    <main>
        <p>Contact page</p>

        <yandex-map :coords="[54.62896654088406, 39.731893822753904]"
                    zoom="10"
                    style="width: 600px; height: 600px;">
            <ymap-marker marker-type="placemark"
                         :coords="[54.62896654088406, 39.731893822753904]"
                         hint-content="Hint content 1"
                         :balloon="{header: 'header', body: 'body', footer: 'footer'}"
                         :icon="{color: 'green', glyph: 'cinema'}"></ymap-marker>

            <ymap-marker marker-type="circle"
                         :coords="[54.62896654088406, 39.731893822753904]"
                         circle-radius="1600"
                         hint-content="Hint content 1"
                         :marker-fill="{color: '#000000', opacity: 0.4}"
                         :marker-stroke="{color: '#ff0000', width: 5}"
                         :balloon="{header: 'header', body: 'body', footer: 'footer'}"></ymap-marker>
        </yandex-map>
    </main>
</template>

<script>
    import Vue from 'vue';
    import YandexMap from 'vue-yandex-maps';
    Vue.use(YandexMap);
</script>

Т.е. что-то не в порядке. Возможно, из-за того, что window.Vue = undefined. При чем, если не указать ни одного ymap-marker, будет ошибка.

PNKBizz commented 7 years ago

Спасибо, проверю. Что-то сделал не так, видимо.

PNKBizz commented 7 years ago

Немного переделал синтаксис импорта. Проблема ушла, я надеюсь )

Gemorroj commented 7 years ago

Покажите тестовый код на котором вы проверяете? Сейчас у меня совсем никак не хочет работать. Я пытаюсь подключить плагин так:

<script>
    import yandexMap from 'vue-yandex-maps';
    import ymapMarker from 'vue-yandex-maps';

    export default {
        components: {
            yandexMap,
            ymapMarker
        }
    }
</script>

Пишет

[Vue warn]: Unknown custom element: <yandex-map> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

PNKBizz commented 7 years ago

Нужно так:

<script>
    import { yandexMap, ymapMarker }  from 'vue-yandex-maps';

    export default {
        components: {
            yandexMap,
            ymapMarker
        }
    }
</script>

Потому как в плагине теперь вместо экспорта по-умолчанию идет экспорт отдельных сущностей.

Gemorroj commented 7 years ago

спасибо, вроде работает.