3

I'm trying to use this in my Blade view. I have .vue file and the following code in JS:

import Multiselect from 'vue-multiselect'

export default {
  components: {
    Multiselect
  },
  data () {
    return {
      value: '',
      options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched']
    }
  }
}

When I add the component in Blade like this:

<div>
   <label class="typo__label">Single select</label>
   <multiselect v-model="value" :options="options" :searchable="false" :close-on-select="false" :show-labels="false" placeholder="Pick a value"></multiselect>
   <pre class="language-json"><code>@{{value}}</code></pre>
</div>

The select doesn't work, it only shows {{value}} string. ¿Any ideas?

6
  • what is the given error in the console? Commented Apr 4, 2017 at 22:14
  • No errors, apparently all works fine. Commented Apr 4, 2017 at 22:18
  • try to remove @ sign Commented Apr 4, 2017 at 22:20
  • If I remove @ blade not recognize {{value}} Commented Apr 4, 2017 at 22:20
  • i would say to create a custom component for this Commented Apr 4, 2017 at 22:26

2 Answers 2

9

Add the parent component to the HTML too, so if you have main app.js it should look like below.

// mycomponent.js

import Multiselect from 'vue-multiselect'

export default {
  components: {
    Multiselect
  },
  data () {
    return {
      value: '',
      options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched']
    }
  }
}

// app.js

var MyComponent = require('./mycomponent');

var app = new Vue({
  el: '#app',
  components: {
    MyComponent
  }
});

// index.blade.php

    <div id="app">
      <my-component inline-template>
        <div>
          <label class="typo__label">Single select</label>
             <multiselect v-model="value" :options="options" :searchable="false" :close-on-select="false" :show-labels="false" placeholder="Pick a value"></multiselect>
           <pre class="language-json"><code>@{{value}}</code></pre>
        </div>
      </my-component>
    </div>

my-component context in the HTML knows and tracks the value.

Here is a fiddle so you can see it in action

const Multiselect = VueMultiselect.Multiselect;

var MyComponent = {
  components: {
    Multiselect
  },
  data() {
      return {
      value: '',
      options: ['Select option', 'options', 'selected', 'mulitple', 'label', 'searchable', 'clearOnSelect', 'hideSelected', 'maxHeight', 'allowEmpty', 'showLabels', 'onChange', 'touched']
    }
  }
};
    
var app = new Vue({
  el: '#app',
  components: {
    MyComponent
  }
});
<link href="https://unpkg.com/[email protected]/dist/vue-multiselect.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://vuejs.org/js/vue.min.js"></script>

<div id="app">
  <my-component inline-template>
    <div>
      <label class="typo__label">Single select</label>
      <multiselect v-model="value" :options="options" :searchable="false" :close-on-select="false" :show-labels="false" placeholder="Pick a value"></multiselect>
      <pre class="language-json"><code>{{value}}</code></pre>
    </div>
  </my-component>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

you need add in your blade:

  <div id="app">
    <your component/>
       your @{{values}} no need to use @
  </div>

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.