在[attach v-menu]中使用多个数据

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

除了属性(附加)外,我还想添加一个类(searchAnchor)。能够使用属性和类的正确拼写是什么?

  ....
  attach: {
                type: [String,Boolean],
                default: false
            },.....
<template>
    <v-menu absolute
            :z-index="zIndex"
            min-width="100%"
            :attach="attach && 'searchAnchor'"
            transition="slide-y-transition"
            :content-class="contentClasses"
            :nudge-bottom="calcHeight"
            :close-on-content-click="false"
            v-on="$listeners"
            :v-bind="$attrs">.....
javascript html vue.js vuetify.js attached-properties
1个回答
1
投票

执行时

:attach="attach && 'searchAnchor'"

Javascript查看变量attach并对其求值。如果求值返回true(在您的情况下,则为true),它将在&&运算符之后返回值-在您的情况下,仅返回'searchAnchor'值。

您想要的是什么

:attach="{ ...attach, searchAnchor: true }"

[这使用spread(...)运算符将对象的属性复制到新对象上,然后向该新对象添加另一个属性searchAnchor,其值为true

© www.soinside.com 2019 - 2024. All rights reserved.