简体   繁体   English

Vue.js 和 Vuetify 插槽范围

[英]Vue.js and Vuetify slot-scope

I'm really just not sure how slot-scopes work.我真的只是不确定插槽范围是如何工作的。 Wondering if somebody could help me out with this (seemingly) pretty simple problem.想知道是否有人可以帮助我解决这个(看似)非常简单的问题。

<v-data-table>
    <template slot="items" slot-scope="props">
        <tr @click="props.expanded = !props.expanded">

What I'm looking to do is manually update "props" to expand this row based on an external event.我要做的是手动更新“道具”以根据外部事件扩展这一行。 The problem is, I can't figure out how to access this outside of the context noted above.问题是,我无法弄清楚如何在上述上下文之外访问它。 The props.expanded = !props.expanded works just fine. props.expanded = !props.expanded工作得很好。

Any ideas?有任何想法吗?

There doesn't seem to be a way built in to the component.该组件似乎没有内置方法。 As the data table creates it's own expanded object and doesn't use a passed in prop.由于数据表创建它自己的扩展对象并且不使用传入的道具。

You can use a ref .您可以使用ref Vue page on child component refs . 子组件 refs 上的 Vue 页面

This following code will set the ref on the data table to accesshere .以下代码会将数据表上的 ref 设置为accesshere

<v-data-table ref="accesshere" :headers="headers" :items="dataTable" 
:search="search" item-key="id">

Now you'll be able to access that object by using (setting this to false will close the expanded table row) this.$refs.accesshere.expanded['nameofkey'] = false现在您可以通过使用(将 this 设置为 false 将关闭展开的表格行) this.$refs.accesshere.expanded['nameofkey'] = false来访问该对象

Here is a codepen showing it in action.这是一个显示它的代码笔

There is an issue with the expanded object and that it isn't populated until you expand a row for the first time.展开的对象存在问题,直到您第一次展开一行时才会填充它。 So if you do something like the following.因此,如果您执行以下操作。 It won't see those changes (unless you force the component to update) and therefore won't expand the row right away.它不会看到这些更改(除非您强制组件更新),因此不会立即展开该行。

 methods: {
   itemShow () {
     this.$refs.accesshere.expanded['2'] = true
     this.$forceUpdate() // This works, I don't know if it is recommended though
  }
 }

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

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