zoukankan      html  css  js  c++  java
  • vue常见表单信息收集

    <!--
    1. 使用v-model(双向数据绑定)自动收集数据
      text/textarea
      checkbox
      radio
      select
    -->
    <div id="demo">
      <form action="/xxx" @submit.prevent="handleSubmit">
        <span>用户名: </span>
        <input type="text" v-model="username"><br>
    
        <span>密码: </span>
        <input type="password" v-model="pwd"><br>
    
        <span>性别: </span>
        <input type="radio" id="female" value="女" v-model="sex">
        <label for="female">女</label>
        <input type="radio" id="male" value="男" v-model="sex">
        <label for="male">男</label><br>
    
        <span>爱好: </span>
        <input type="checkbox" id="basket" value="basket" v-model="likes">
        <label for="basket">篮球</label>
        <input type="checkbox" id="foot" value="foot" v-model="likes">
        <label for="foot">足球</label>
        <input type="checkbox" id="pingpang" value="pingpang" v-model="likes">
        <label for="pingpang">乒乓</label><br>
    
        <span>城市: </span>
        <select v-model="cityId">
          <option value="">未选择</option>
          <option :value="city.id" v-for="(city, index) in allCitys" :key="city.id">{{city.name}}</option>
        </select><br>
        <span>介绍: </span>
        <textarea rows="10" v-model="info"></textarea><br><br>
    
        <input type="submit" value="注册">
      </form>
    </div>
    
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript">
      new Vue({
        el: '#demo',
        data: {
          username: '',
          pwd: '',
          sex: '男',
          likes: ['foot'],
          allCitys: [{id: 1, name: 'BJ'}, {id: 2, name: 'SS'}, {id: 3, name: 'SZ'}],
          cityId: '2',
          info: ''
        },
        methods: {
          handleSubmit () {
            console.log(this.username, this.pwd, this.sex, this.likes, this.cityId, this.info)
            alert('提交注册的ajax请求')
          }
        }
      })
    </script>
    

  • 相关阅读:
    AppDelegate减负之常用三方封装
    AppDelegate减负之常用三方封装
    基于AFN封装的带缓存的网络请求
    iOS-创建自己的日志系统
    UIImage 图片处理:截图,缩放,设定大小,存储
    /bin/sh^M: bad interpreter:解决办法
    mac上获取手机的uuid
    iOS PureLayout使用
    iOS集成友盟推送
    完全理解Python的 '==' 和 'is'
  • 原文地址:https://www.cnblogs.com/chenxi188/p/14515913.html
Copyright © 2011-2022 走看看