我正在尝试在我的 Blade 视图中使用它。我.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']
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我像这样在 Blade 中添加组件时:
<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>
Run Code Online (Sandbox Code Playgroud)
选择不起作用,它只显示{{value}}字符串。有任何想法吗?
小智 7
也将父组件添加到 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']
}
}
}
Run Code Online (Sandbox Code Playgroud)
// app.js
var MyComponent = require('./mycomponent');
var app = new Vue({
el: '#app',
components: {
MyComponent
}
});
Run Code Online (Sandbox Code Playgroud)
// 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>
Run Code Online (Sandbox Code Playgroud)
my-component HTML 中的上下文知道并跟踪该值。
这是一个小提琴,所以你可以看到它在行动
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
}
});Run Code Online (Sandbox Code Playgroud)
<link href="https://unpkg.com/vue-multiselect@2.0.0-beta.14/dist/vue-multiselect.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/vue-multiselect@2.0.0-beta.14"></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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21468 次 |
| 最近记录: |