Vue.js - Buefy Modules(Radio btns / Check Box)

时间:2018-05-07 14:06:51

标签: laravel vue.js vuejs2 vue-component laravel-5.6

我在Laravel练习后端,前端我正在使用Vue.js - Buefy Modules,我对Radio和CheckBox没什么问题。

此处用户应选择两个提供的无线电bt中的一个:

<div class="block">
      <b-radio-group v-model="permissionType">
          <b-radio name="permission_type" value="basic">Basic Permission</b-radio>
          <b-radio name="permission_type" value="crud">CRUD Permission</b-radio>
      </b-radio-group>
  </div>

如果用户点击第一个btun(基本),则会出现3个输入字段:

<div class="field" v-if="permissionType == 'basic'">
   <label for="display_name" class="label">Name (Display Name)</label>
   <p class="control">
     <input type="text" class="input" name="display_name" id="display_name">
   </p>
</div>

      <div class="field" v-if="permissionType == 'basic'">
        <label for="name" class="label">Slug</label>
        <p class="control">
          <input type="text" class="input" name="name" id="name">
        </p>
      </div>

      <div class="field" v-if="permissionType == 'basic'">
        <label for="description" class="label">Description</label>
        <p class="control">
          <input type="text" class="input" name="description" id="description" placeholder="Describe what this permission does">
        </p>
      </div>

如果用户点击第二个btn(CRUD),则会出现1个输入,4个复选框btns和表格,但它们不会出现。

<div class="field" v-if="permissionType == 'crud'">
        <label for="resource" class="label">Resource</label>
        <p class="control">
          <input type="text" class="input" name="resource" id="resource" v-model="resource" placeholder="The name of the resource">
        </p>
      </div>

      <div class="columns" v-if="permissionType == 'crud'">
        <div class="column is-one-quarter">
          <b-checkbox-group v-model="crudSelected">
            <div class="field">
              <b-checkbox custom-value="create">Create</b-checkbox>
            </div>
            <div class="field">
              <b-checkbox custom-value="read">Read</b-checkbox>
            </div>
            <div class="field">
              <b-checkbox custom-value="update">Update</b-checkbox>
            </div>
            <div class="field">
              <b-checkbox custom-value="delete">Delete</b-checkbox>
            </div>
          </b-checkbox-group>
        </div> <!-- end of .column -->

        <input type="hidden" name="crud_selected" :value="crudSelected">

        <div class="column">
          <table class="table" v-if="resource.length >= 3">
            <thead>
              <th>Name</th>
              <th>Slug</th>
              <th>Description</th>
            </thead>
            <tbody>
              <tr v-for="item in crudSelected">
                <td v-text="crudName(item)"></td>
                <td v-text="crudSlug(item)"></td>
                <td v-text="crudDescription(item)"></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

我已经检查了Buefy文档并且有一些更新,但是当我更改代码时,仍然无法正常工作..

这是脚本:

  <script>
        var app = new Vue({
          el: '#app',
          data: {
            permissionType: 'basic',
            resource: '',
            crudSelected: ['create', 'read', 'update', 'delete']
          },
          methods: {
            crudName: function(item) {
              return item.substr(0,1).toUpperCase() + item.substr(1) + " " + app.resource.substr(0,1).toUpperCase() + app.resource.substr(1);
            },
            crudSlug: function(item) {
              return item.toLowerCase() + "-" + app.resource.toLowerCase();
            },
            crudDescription: function(item) {
              return "Allow a User to " + item.toUpperCase() + " a " + app.resource.substr(0,1).toUpperCase() + app.resource.substr(1);
            }
          }
        }); 
    </script>

在这里我放置原始代码而不做任何更改,如果有人能解决这个问题,我将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

您忘记将v-model添加到您的广播组,尝试此操作并且它应该可以正常工作

<div class="block">
  <b-radio-group v-model="permissionType">
      <b-radio v-model="permissionType" name="permission_type" native-value="basic">Basic Permission</b-radio>
      <b-radio v-model="permissionType" name="permission_type" native-value="crud">CRUD Permission</b-radio>
  </b-radio-group>