Vue 常用功能实现
#
Vue中获取input输入框值的两种方式ref
获取input
框的值#
1. 使用<template> <div> <div class="logininfor"> <input type="text" placeholder="手机号码" ref="userphone"> <input type="text" placeholder="密码" ref="userpass"> <span @click="register()">注册</span> </div> <p>已有账号?去<span class="zhuce" @click="login()">登录</span></p> </div> <script>
export default { methods: { register(){ window.console.log(this.$refs.userphone.value) window.console.log(this.$refs.userpass.value) } }, }</script></template>
v-model
双向绑定,完成input
框值获取。#
2. 通过<template> <div> <div class="logininfor"> <input type="text" placeholder="手机号码" v-model="userphone"> <input type="text" placeholder="密码" v-model="userpass"> <span @click="register()">注册</span> </div> <p>已有账号?去<span class="zhuce" @click="login()">登录</span></p> </div></template><script>
export default { data(){ return{ userphone:"", userpass:"" } }, methods: { register(){ window.console.log(this.userphone,this.userpass) } }, }</script>