我正忙着使用Vue.js创建一个动态表单,此刻,除了remove函数之外,我看起来一切都正确。据我所知,它已正确配置,但浏览器中的控制台显示错误“this.rows。$ remove不是函数”。
有没有人知道这方面的解决方案,还是可以帮我找到解决方案?提前谢谢。
======================================
以下是显示表单的页面的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']) !!}
答案 0 :(得分:1)
在vue 2.0中看起来$remove
方法已被弃用,所以我假设您正在使用它。您将需要使用拼接:
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);
}
你可以在这里看到小提琴:https://jsfiddle.net/rLes3nww/
答案 1 :(得分:0)
引用指南然后发现它已被弃用真的很烦人。
无论如何,我发现这是一个被弃用的参考。 Reference to deprecated Vue stuff