刀片中的Vue组件

问题描述 投票:0回答:1

我在刀片视图中尝试使用this。我有.vue文件和这个代码在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']
    }
  }
}

当我在刀片中添加这样的组件时

<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>

选择不起作用,只显示{{value}}字符串。 ¿有关错误的想法吗? `

laravel vue.js
1个回答
1
投票

您还需要将父组件添加到HTML中,因此如果您有主app.js,它应该如下所示。

// 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>

所以html中的“my-component”上下文知道并跟踪这里的值是一个小提琴,所以你可以看到它在行动。

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>
© www.soinside.com 2019 - 2024. All rights reserved.