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

标签 javascript html templates vue.js drop-down-menu

我想使用this我的基于 vue.js 的网络项目的下拉菜单。 到目前为止,vue.js 的一切都运行良好。

不幸的是,在下面的示例中,模板部分(我猜)没有被渲染。控制台中没有错误消息,我不知道需要做什么才能使用 <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>

任何提示都将受到高度赞赏!

最佳答案

在链接中,他这样说

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

因此将您的代码更新为

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

因为 Vue 读取 <template>标签,所以不要在代码中使用它

关于javascript - vue.js 的 <template> 语法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53572704/

相关文章:

javascript - 到达 id 时更改 CSS

javascript - JSDoc:属性名称

javascript - pdf object.messagehandler onMessage 在 IE 中不工作

html - 为移动设备调整堆叠列的高度 (@media)

C++11模板解析错误,使用模板别名进行类型推导

javascript - 无法使用 onclick 属性调用函数

javascript - DevExtreme dxList 在鼠标悬停时更改 itemTemplate

javascript - 单击按钮移动 div 左/右视口(viewport)宽度

c++ - 为什么实例化函数模板可以(隐式)使用未声明的符号?

c++ - 使用模板转换特定类型的参数