vue.js array into Django

折月煮酒 提交于 2021-01-29 14:42:09

问题


So I want to go through my array which ive crated on vue.js and then check against the arrary to decide where to save it. To explain it a bit more here's the code i have so far

Vue.js

var app= new Vue({
  el: '.con',
    data:{
      posts: [
      {
        title:'',
        content:'',
        type:''
      }
    ],
    },
    methods:{
      addHead(index){
        this.posts.push({
          content:'',
          type:'header',
        })
      },
      addPara(index){
        this.posts.push({
          content:'',
          type:'para',
        })
      },
      removeForm(){
        this.posts.splice(index, 1)
      }
    }
})

HTML

<div class="con">

  <button type="button" name="button" @click='addHead()'>
      header
  </button>
  <button type="button" name="button" @click='addPara()'>
      Para
  </button>
  <input type="text" name="" placeholder="Title"
    v-models='posts.title'>
    <div id="body-fields">
      <div class="car-body" v-for="(post, index) in posts">
        <input type="textbox" name="" placeholder='{{post.type}}'
          v-models='post.content'>
        <span style="float:right;background-color:green"
          @click='removeForm(index)'>
            x
        </span>
      </div>
    </div>
  </div>

So i want to save the posts array depending on the type so if its a header save it to one model and if its the other type save it to another, i'm using python and django, thanks for any help

来源:https://stackoverflow.com/questions/60536343/vue-js-array-into-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!