简体   繁体   English

<template> vue.js的语法不起作用

[英]<template> syntax of vue.js does not work

I want to use this dropdown menue for my webproject based on vue.js. 我想在基于vue.js的Web项目中使用下拉菜单。 Everything with vue.js worked fine so far. 到目前为止,vue.js的所有功能都可以正常工作。

Unfortunately in the following example the template part does (i guess) not get rendered. 不幸的是,在以下示例中,模板部分确实(我想)没有被渲染。 There is no error message in the console and i don't know what i need to do to use <template> properly in my webproject. 控制台中没有错误消息,我不知道要在我的Web项目中正确使用<template>我需要做什么。

<div>
  <label class="typo__label">Simple select / dropdown</label>
  <multiselect v-model="value" :options="options" :multiple="true" :close-on-select="false" :clear-on-select="false" :preserve-search="true" placeholder="Pick some" label="name" track-by="name" :preselect-first="true">
    <template slot="selection" slot-scope="{ values, search, isOpen }"><span class="multiselect__single" v-if="values.length &amp;&amp; !isOpen">{{ values.length }} options selected</span></template>
  </multiselect>
  <pre class="language-json"><code>{{ value  }}</code></pre>
</div>

Any hint is highly appreciated! 任何提示高度赞赏!

In the link, he says that 在链接中,他说

<template slot="tag" slot-scope="props"><Your code></template>

so update your code to 所以将您的代码更新为

<template slot="selection" slot-scope="{ values, search, isOpen }">
    <div>
    <label class="typo__label">Simple select / dropdown</label>
    <multiselect v-model="value" :options="options" :multiple="true" :close-on-select="false" :clear-on-select="false" :preserve-search="true" placeholder="Pick some" label="name" track-by="name" :preselect-first="true">
        <span class="multiselect__single" v-if="values.length &amp;&amp; !isOpen">{{ values.length }} options selected</span>
    </multiselect>
    <pre class="language-json"><code>{{ value }}</code></pre>
    </div>
</template>

because Vue read from <template> tag so don't use it inside codes 因为Vue从<template>标记读取,所以不要在代码内部使用它

Since the template tag is within the mulitselect, I'd suggest you check the documentation for vue-multiselect and check out their slot scopes. 由于模板标记位于mulitselect中,因此建议您查看vue-multiselect的文档并查看其插槽范围。 This should help https://vue-multiselect.js.org/#sub-getting-started 这应该有助于https://vue-multiselect.js.org/#sub-getting-started

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM