小编Ash*_*JIT的帖子

Vue 复选框不随数据更改而更新

我在 Vue 更新 UI 中的数据出现问题,但似乎只有复选框存在此问题。

我试图一次只允许选中一个复选框,因此我在单击其中之一时将所有复选框设置为 false。但是,这在数据中有效,但在复选框中无法正确呈现。

HTML:

<table class="buildings-modify--table table-full table-spacing">
    <thead>
       <tr>
          <th>Name</th>
          <th>Primary</th>
          <th>Address</th>
          <th>City/Town</th>
          <th>Province</th>
          <th>Postal Code</th>
          <th>Phone</th>
          <th>Active</th>
       </tr>
     </thead>
     <tbody>
       <tr v-for="landlord in selectedLandlords" :key="landlord.id">
         <td>{{ landlord.name }}</td>
         <td>                            
           <input type="checkbox" :value="landlord.is_primary" @change.prevent="makePrimaryLandlord(landlord)">
         </td>
         <td>{{ landlord.address }}</td>
         <td>{{ landlord.city }}</td>
         <td>{{ landlord.province}}</td>
         <td>{{ landlord.postal_code}}</td>
         <td>{{ landlord.phone }}</td>
         <td>{{ landlord.is_active ? "Yes" : "No" }}</td>
       </tr>
   </tbody>
Run Code Online (Sandbox Code Playgroud)

视图代码:

export default {
    data: function() {
        return {
            selectedLandlords: []
        }
    },
    methods: {
        makePrimaryLandlord: function(landlord) { …
Run Code Online (Sandbox Code Playgroud)

checkbox vue.js

7
推荐指数
1
解决办法
9141
查看次数

标签 统计

checkbox ×1

vue.js ×1