我正在查看VUES页面上的教程,以添加工具提示。https://vuetifyjs.com/en/components/tooltips
对于一个单独的按钮来说,它似乎工作得很好。
但是,它在v项中不起作用。我收到一条控制台消息说
“[vuetify]v-item缺少默认scopedslot”

<v-item v-for="foo in bars" :key=`${foo}`>
  <v-tooltip>
    <v-btn slot="activator">
      <v-icon>some-icon</v-icon>
    </v-btn>
    <span>Some tooltip text</span>
  </v-tooltip>
</v-item>

我试过在上面的代码中添加一些东西,比如slot=“activator”添加到v-item,slot scope=“activator”添加到v-btn,但似乎没有什么工作得很好。关于我做错了什么有什么建议吗?
@boussadjarabrahim添加的运行片段:
new Vue({
  el: '#app',
  data() {
    return {
      bars: ['a', 'b', 'c']
    }
  }

})

<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css">
<div id="app">
  <v-item-group>
    <v-container grid-list-md>
      <v-layout wrap>
        <v-flex v-for="(n,i) in bars" :key="n" xs12 md4>
          <v-item>
            <v-tooltip>
              <v-btn slot="activator">
                <v-icon>home</v-icon>
              </v-btn>
              <span>Some tooltip text {{n}}</span>
            </v-tooltip>
          </v-item>
        </v-flex>
      </v-layout>
    </v-container>
  </v-item-group>

</div>

最佳答案

在调试代码片段之后,我通过将slot-scope="i"添加到tooltip组件(如<v-tooltip slot-scope="i" right>中)找到了解决方案:

new Vue({
  el: '#app',
  data() {
    return {
      bars: ['home', 'event', 'info']
    }
  }

})

<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css">
<div id="app" data-app>
  <v-item-group >
    <v-container grid-list-md>
      <v-layout wrap>
        <v-flex v-for="(n,i) in bars" :key="n" xs12 md4>
          <v-item     >
            <v-tooltip   slot-scope="i" right>
              <v-btn slot="activator">
                <v-icon>{{n}}</v-icon>
              </v-btn>
              <span>{{n}}</span>
            </v-tooltip>
          </v-item>
        </v-flex>
      </v-layout>
    </v-container>
  </v-item-group>

</div>

关于javascript - 缺少默认作用域的插槽,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54094579/

10-09 21:28