如何将类添加到vue中的“模板”标签?

Ato*_*abi 4 vue.js

我需要知道如何将类添加到 vue 中的“模板”标签。

<template 
  #popover
  class: templateClass // Is it possible to add a class in here?
>
  <router-link
    v-close-popover
    to="/somewhere"
  >
    Go to the page
  </router-link>
</template>
Run Code Online (Sandbox Code Playgroud)

Bra*_*aks 6

您无法将任何类绑定到模板标记,因为模板标记本身不会为自身呈现元素。尽管提出了相反的评论,但您想要实现的目标是不可能的。Vue2 的组件需要一个根元素是有原因的。添加#templateRef到 template-tag 只是 v-slot 的简写(请参阅Vue 中井号 (#) 的含义是什么?),在这种情况下基本上对您没有任何作用。