vue.js 没有删除行

vue.js not removing row

我正忙于使用 Vue.js 制作动态表单,目前,除了删除功能外,我似乎一切正常。据我所知,一切都已正确配置,但浏览器中的控制台显示错误 "this.rows.$remove is not a function".

有谁知道这个问题的解决方案,或者可以帮我找到解决方案吗?提前致谢。

======================================

这是显示表单的页面的 HTML:

<html>  
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>M06 Property-create</title>

    <!-- Including nessecary javascript sources -->
    <script src="https://unpkg.com/vue@next/dist/vue.js"></script>

</head>


{!! Form::open(array('route' => 'property.store')) !!}

@include('properties.form')

{!! Form::close() !!}

<a href="/property">Return</a>

<script> //This script handles the adding / removal of label/text fields upon clicking the add label / remove label button
    var app = new Vue({
        el: "#app",
        data: {
            rows: [
                {name: ""}
            ]
        },
        methods: {
            addRow: function () {
                this.rows.push({name: ""});
            },
            removeRow: function (row) {
                console.log(row);
                this.rows.$remove(row);
            }
        }
    });
</script>

</body>
</html>

======================================

这是包含的表单本身的 HTML / Blade:

{!! Form::label('label', Lang::get('misc.label')) !!}
{!! Form::text('label', null, ['class' => 'form-control', 'required']) !!}
<br>
{!! Form::label('internal_name', Lang::get('misc.internal_name')) !!}
{!! Form::text('internal_name', null, ['class' => 'form-control', 'required']) !!}
<br>
{!! Form::label('field_type_id', Lang::get('misc.fieldtype_name')) !!}
{!! Form::select('field_type_id', $fieldTypes) !!}

<div class="dropdown box">
<div class="multi-field-wrapper">

    <div class="multi-fields">
        <div class="multi-field">

            <div id="app">
                <table class="table">
                    <thead>
                    <button type="button" class="button btn-primary" @click="addRow">Add label</button>

                    <tr>
                        <td><strong>Label</strong></td>
                        <td></td>
                    </tr>
                    </thead>
                    <tbody>
                        <tr v-for="row in rows">
                            <td><input type="text" v-model="row.name"></td>
                            <td><button type="button" class="button btn-primary" @click="removeRow(row)">Remove</button></td>
                        </tr>
                    </tbody>
                </table>
            </div>    

        </div>
    </div>
 </div>
 </div>
<br>
{!! Form::label('property_group_id', Lang::get('misc.group_name')) !!}
{!! Form::select('property_group_id', $groups) !!}
<br>         
{!! Form::label('description', Lang::get('misc.description')) !!}
{!! Form::textarea('description', null, ['class' => 'form-control', 'required']) !!}
<br>
<br>
{!! Form::submit(Lang::get('misc.save'), ['class' => 'btn btn-success', 'id' => 'btn-save']) !!}

看起来 $remove 方法在 vue 2.0 中已被弃用,所以我假设您正在使用它。您将需要改用拼接:

HTML:

<tr v-for="(row, index) in rows">
  <td><input type="text" v-model="row.name"></td>
  <td><button type="button" class="button btn-primary" @click="removeRow(index)">Remove</button></td>
</tr>

Javascript:

removeRow: function (index) {
  console.log(index);
  this.rows.splice(index,1);
}

您可以在此处查看 fiddle:https://jsfiddle.net/rLes3nww/

参考指南然后发现它已被弃用,真是令人恼火。

不管怎样,我发现这是一个参考,它是被弃用的还是不被弃用的。 Reference to deprecated Vue stuff