很抱歉,我无法提供太多信息,因为我真的不知道为什么这不起作用,我正在尝试打印索引,但由于某种原因索引根本不起作用,感谢任何帮助。索引在任何时候都没有任何值,永远不会打印任何值。
HTML页面
{% extends 'blog/base.html' %}
{% block content %}
{% load static %}
<form method="post"> {% csrf_token %}
<div class="con">
<button type="button" name="button" @click='addHead()'>
header
</button>
<button type="button" name="button" @click='addPara()'>
Para
</button>
<div id="body-fields">
<div class="car-body" v-for="(post, index) in posts">
<div name='count'>
{{index}}
</div>
<input type="textbox" v-bind:name='[post.type]' v-model='post.content'>
<span style="float:right;background-color:green" @click='removeForm(index)'>
x
</span>
</div>
</div>
<input type="submit" vaule="save"/>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="{% static 'blog/JS/main.js'%}" type="text/javascript"></script>
{% endblock content %}
Vue.js 页面
var app= new Vue({
el: '.con',
data:{
posts: [
{
content:'',
type:'title'
}
],
},
methods:{
addHead(index){
this.posts.push({
content:'',
type:'header',
})
},
addPara(index){
this.posts.push({
content:'',
type:'para',
})
},
removeForm(){
this.posts.splice(index, 1)
}
}
})
慕容森
largeQ
相关分类