2

I don't have a whole vue app, so I use custom elements to replace some elements that should be handled with vue.

I simply want to use the vue multiselect plugin in a html file.

So I tried the following:

index.ts

import Vue from "vue"
import VueCustomElement from 'vue-custom-element'
import Autocomplete from "./vue/autocomplete.vue"

Vue.use(VueCustomElement);
Vue.customElement('auto-complete', Autocomplete);

test.html

<auto-complete
        v-model="value"
        :options="options"
        placeholder="test"
        @search-change="getData"
>
</auto-complete>

test.vue

<template>
    <multiselect v-model="value" :options="options" @search-change="getData"></multiselect>
</template>

<script type="ts">
    const Multiselect = require('vue-multiselect').default

    export default {
        components: { Multiselect },
        data () {
            return {
                value: 'test',
                options: ['list', 'of', 'options']
            }
        },
        methods: {
            getData (query) {
                console.log(123)
            }
        }
    }
</script>

<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>

In the output the data of the custom element is always ignored and only the parameters in the part in the .vue file is used.

How can i achieve that the parameters like placeholder or @search-change are used from the custom element?

1
  • Remember that :options="options" and @search-change won't work in regular HTML as this are Vue specific solutions. Commented Apr 6, 2018 at 8:10

1 Answer 1

1

I am also using vue-custom-elements in one of my projects.

You are passing option as props so you need to add it as a prop in your autocomplete.vue.

<template>
    <multiselect v-model="value" :options="options" @search-change="getData"></multiselect>
</template>

<script type="ts">
    const Multiselect = require('vue-multiselect').default

    export default {
        props: ['options'],
        components: { Multiselect },
        data () {
            return {
                value: 'test'
            }
        },
        methods: {
            getData (query) {
                console.log('123')
            }
        }
    }
</script>

<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.