代码之家  ›  专栏  ›  技术社区  ›  user1093111

通过在vuejs中弹出表单模式来编辑表中的特定行

  •  0
  • user1093111  · 技术社区  · 7 年前

    <v-data-table
        v-bind:headers="headers"
        v-bind:items="packets"
        v-bind:search="search"
      >
      <template slot="items" scope="props">
        <td>
           {{ props.item.name }}
        </td>
        <td class="text-xs-right">{{ props.item.folder }}</td>
        <td class="text-xs-right">
            <EditPacketDialog></EditPacketDialog> <!-- #### NEED TO PASS IN PROPS DATA. HOW? -->
        </td>
      </template>
      <template slot="pageText" scope="{ pageStart, pageStop }">
        From {{ pageStart }} to {{ pageStop }}
      </template>
    </v-data-table>
    

    当我点击表格上的编辑按钮时,我想显示一个表格:

    <template>
      <v-layout right row >
        <v-dialog v-model="dialog" width="50%">
          <v-btn outline small fab slot="activator" class="indigo--text" @click="editPacket">
            <v-icon>edit</v-icon>
          </v-btn>
          <v-card>
            <v-card-title>
              <span class="headline">Edit Packet</span>
            </v-card-title>
            <v-card-text>
              <v-text-field label="Name" required></v-text-field><!-- #### SET THE FIELD -->
              <v-select
                label="Documents"
                multiple
                autocomplete
                chips
                :items="['WorkTime', 'Firm & Branch Financials', '2017 Firm Financial Letter', 'Systems Ideas', 'MyFirstDocument']"
              ></v-select>
              <small>*indicates required field</small>
            </v-card-text>
            <v-card-actions>
              <v-spacer></v-spacer>
              <v-btn class="blue--text darken-1" flat @click.native="dialog = false">Close</v-btn>
              <v-btn class="blue--text darken-1" flat @click.native="dialog = false">Save</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>
      </v-layout>
    </template>
    
    <script>
      export default {
        data () {
          return {
            dialog: false
          }
        }
      }
    </script>
    

    由于对话框(表单)太大,我想将其从表代码中分离出来,但是,我不确定如何传递道具。项目名称和道具。项目将文件夹放入子组件中。识别要编辑的行/数据的正确方法是什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   tony19 RuNpiXelruN    2 年前

    您可以像这样向模板传递道具:

    <EditPacketDialog v-bind:item="props.item"></EditPacketDialog>
    

    然后在模板中,你需要收到一个名为“item”的道具。这将有 item.folder item.name 供您在模板中使用。

    Check out the Vuejs documentation if you need help receiving the props in your template .