码迷,mamicode.com
首页 > 其他好文 > 详细

VUE学习四【自动获取提交的数据,生命周期】

时间:2020-02-18 13:19:00      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:code   checkbox   script   inter   pass   person   box   ack   value   

<div id="demo">
  <form @submit.prevent="handleSubmit">
    <span>用户名:</span>
    <input type="text" v-model="user.username">
    <br>
    <span>密码:</span>
    <input type="password" v-model="user.pwd">
    <br>
    <span>性别:</span>
    <input type="radio" id="female" value="female" v-model="user.sex">
    <label for="female"></label>
    <input type="radio" id="male" value="male" v-model="user.sex">
    <label for="male"></label>
    <br>
    <span>爱好:</span>
    <input type="checkbox" id="basket" value="basketball" v-model="user.likes">
    <label for="basket">篮球</label>
    <input type="checkbox" id="foot" value="football" v-model="user.likes">
    <label for="foot">足球</label>
    <input type="checkbox" id="pingpang" value="pingpang" v-model="user.likes">
    <label for="pingpang">乒乓</label>
    <br>
    <span>城市:</span>
    <select v-model="user.cityId">
      <option value="">未选择</option>
      <option v-for="city in allCitys" :value="city.id">{{ city.name }}</option></select>
    <br>
    <span>介绍:</span>
    <textarea v-model="user.desc" rows="10"></textarea>
    <br>
    <br>
    <input type="submit" value="注册"></form>
</div>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript">var vm = new Vue({
    el: #demo,
    data: {
      user: {
        username: ‘‘,
        pwd: ‘‘,
        sex: female,
        likes: [],
        cityId: ‘‘,
        desc: ‘‘,
      },
      allCitys: [{
        id: 1,
        name: BJ
      },
      {
        id: 2,
        name: SZ
      },
      {
        id: 4,
        name: SH
      }],
    },
    methods: {
      handleSubmit(event) {
        alert(JSON.stringify(this.user))
      }
    }
  })</script>
<div>
  <button @click="destoryVue">destory vue</button>
  <p v-show="isShowing">{{msg}}</p></div>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript">var vue = new Vue({
    el: div,
    data: {
      msg: 尚硅谷 IT 教育,
      isShowing: true,
      persons: []
    },
    beforeCreate() {
      console.log(beforeCreate() msg= + this.msg)
    },
    created() {
      console.log(created() msg= + this.msg) this.intervalId = setInterval(() = >{
        console.log(-----) this.isShowing = !this.isShowing
      },
      1000)
    },
    beforeMount() {
      console.log(beforeMount() msg= + this.msg)
    },
    mounted() {
      console.log(mounted() msg= + this.msg)
    },
    beforeUpdate() {
      console.log(beforeUpdate isShowing= + this.isShowing)
    },
    updated() {
      console.log(updated isShowing= + this.isShowing)
    },
    beforeDestroy() {
      console.log(beforeDestroy() msg= + this.msg) clearInterval(this.intervalId)
    },
    destroyed() {
      console.log(destroyed() msg= + this.msg)
    },
    methods: {
      destoryVue() {
        vue.$destroy()
      }
    }
  })</script>

 技术图片

 

VUE学习四【自动获取提交的数据,生命周期】

标签:code   checkbox   script   inter   pass   person   box   ack   value   

原文地址:https://www.cnblogs.com/wangchuang/p/12325575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!