gpt4 book ai didi

javascript - 在常规 html 页面中使用 vue-multiselect.js

转载 作者:行者123 更新时间:2023-12-03 01:54:55 25 4
gpt4 key购买 nike

我正在尝试在常规 html 页面中使用 vue-multiselect.js 。它不工作。这是我的代码:

<script src="https://unpkg.com/vue-multiselect@2.1.0"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-multiselect@2.1.0/dist/vue-multiselect.min.css">


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

<script type="text/javascript">
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']
}
}
}
</script>

这就是它在控制台中写入的内容 - Uncaught SyntaxError: Unexpected identifier in line 12

最佳答案

你都做错了。这是这个概念的工作代码:

HTML:

<div id="app">
<multiselect
v-model="value"
:options="options"
:multiple="true"
track-by="library"
:custom-label="customLabel"
>
</multiselect>
<pre>{{ value }}</pre>
</div>

Javascript:

new Vue({
components: {
Multiselect: window.VueMultiselect.default
},
data: {
value: { language: 'JavaScript', library: 'Vue-Multiselect' },
options: [
{ language: 'JavaScript', library: 'Vue.js' },
{ language: 'JavaScript', library: 'Vue-Multiselect' },
{ language: 'JavaScript', library: 'Vuelidate' }
]
},
methods: {
customLabel (option) {
return `${option.library} - ${option.language}`
}
}
}).$mount('#app')

Jsfiddle

关于javascript - 在常规 html 页面中使用 vue-multiselect.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50284978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com