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

<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>

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

时间: 2024-08-30 17:31:42

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

Android学习路线(十五)Activity生命周期——重新创建(Recreating)一个Activity

先占个位置,下次翻译~ :p There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish(). The system may also destroy your

Android学习路线(十二)Activity生命周期——启动一个Activity

先占个位置,过会儿来翻译,:p Unlike other programming paradigms in which apps are launched with a main()method, the Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle. Th

Vue学习小结(一)安装依赖与数据来源

不多说啥了,生活中都是各种阵痛与惊喜.最近在学习vue框架,刚写完一个小型的后台管理系统(https://github.com/michaelzhengzm/info-manager-systerm_ol),在这里做一个阶段性的小结: 一.构建项目与安装依赖 构建项目采用vue-cli脚手架搭建,npm.cnpm.vue-cli这些知识的基础,网上一大片一大片的,就不过多的描述了.难理解的是里面的配置文件,初学的时候确实费了很多劲,先不用去管太多的配置文件,这些主要是以后上线打包的一些配置问题.

Android学习笔记(三三):Activity生命周期

Android很大的应用场景是手机,有一些应用具有特别的优先级别,例如电话,同时设备的内存是有限的.因在某些情况下系统将踢走activity,以便是否内存.因此在开发过程中,我们需要管理好activity的生命周期.右图是Android的docs中提供的activity的时间触发图. 四大状态 一般来讲,某一时刻,Activity处在下面四个状态之一: Active:已由用户启动,正在前台运行. Paused:已由用户启动,正在运行且可视,但是由于提示或者其他覆盖部分的屏幕.这是用户可以看到ac

Android学习笔记(五)——活动的生命周期

//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 为了能写出流畅连贯的程序,我们需要了解一下活动的生命周期. 一.返回栈 Android 中的活动是可以层叠的.我们每启动一个新的活动,就会覆盖在原活动之上,然后点击 Back 键会销毁最上面的活动.事实上,Android 是使用任务(Task)来管理活动的,一个任务就是一组存放在栈里的活动的集合,这个栈也被称作返回栈(Back Stack) .默认情况下,每当我们启动了一个新的活动,它会在返回栈中入栈,并处于栈顶的位

shell中的数据生命周期scope

#!/bin/shexit 0#shell 中, 默认所有的变量都是 全局变量,除非主动变量前面加 local 修饰#shell 变量是字符变量,只能放字符和数字,shell数组也是如此;而数字也是图形字符;总的来说,shell的变量是图形字符变量#变量,函数和系统命令可以同名,先搜索脚本后系统环境 #子进程拥有父进程的环境副本,但不能影响父进程的环境;子进程能对父进程的环境有读权限.写的时候,只是在自己的副本中生效,一种写时复制的形式;脚本都是进程,函数不是;#函数完全共享调用者的环境,并且能

Spark版本定制第10天:流数据生命周期和思考

本期内容: 1 数据流生命周期 2 深度思考 一切不能进行实时流处理的数据都是无效的数据.在流处理时代,SparkStreaming有着强大吸引力,而且发展前景广阔,加之Spark的生态系统,Streaming可以方便调用其他的诸如SQL,MLlib等强大框架,它必将一统天下. Spark Streaming运行时与其说是Spark Core上的一个流式处理框架,不如说是Spark Core上的一个最复杂的应用程序.如果可以掌握Spark streaming这个复杂的应用程序,那么其他的再复杂的

Struts2学习第二天——获取参数与数据校验

文档版本 开发工具 测试平台 工程名字 日期 作者 备注 V1.0 2016.06.14 lutianfei none struts2中获取请求参数 在struts2中action是什么?(struts2是一个mvc框架) View : jsp Model : action Control : action & StrutsPrepareAndExecuteFilter 1.属性驱动 1.直接将action做一个model(类似bean结构),就可以得到请求参数. 问题1:action封装请求参

vue 学习四 了解组件

1组件的注册 全局注册 import Vue from 'vue'; import com from './component1'; Vue.component("com_name",com)//第一个参数是你为注册的组件定义一个id,第二个是你要注册的组件 局部注册 //在组件内 import com from "../components/a_component"; export default { name: "home", compone