21-Vue之Element UI-input组件

目录

组件使用

总结


组件使用

<template>
  <div>
    <h2>这是Input组件</h2>
    <el-input v-model="input" placeholder="请输入内容"></el-input>
    <el-input disabled placeholder="请输入内容"></el-input>
    <el-input type="textarea" placeholder="请输入内容"></el-input>
    <el-input v-model="input" size="medium" :maxlength="10" show-word-limit clearable placeholder="请输入内容"></el-input>
    <el-input type="password" placeholder="请输入密码" v-model="input" show-password></el-input>
    <!--    事件使用-->
    <h2>事件使用</h2>
    <el-input v-model="username" @blur="changeBlur" @focus="changeFocus"></el-input>
    <el-input v-model="password" @change="changed"></el-input>
    <!--    方法使用-->
    <h2>方法使用</h2>
    <el-input v-model="mes" ref="method"></el-input>
    <el-button @click="focusInput">focus方法</el-button>
    <el-button @click="blurInput">blur方法</el-button>
    <el-button @click="selectInput">select方法</el-button>
  </div>
</template>

<script>
export default {
  name: 'Input',
  data () {
    return {
      input: '',
      username: '',
      password: '',
      mes: ''
    }
  },
  methods: {
    changeBlur () {
      console.log(this.username)
    },
    changeFocus () {
      console.log(this.username)
    },
    changed () {
      console.log(this.password)
    },
    focusInput () {
      this.$refs.method.focus()
    },
    blurInput () {
      this.$refs.method.blur()
    },
    selectInput () {
      this.$refs.method.select()
    }
  }
}
</script>

<style scoped>

</style>

总结

  • 在使用组件的方法时需要在对应的组件中加入ref=“组件别名”
  • 在调用方法时直接使用this.$refs.组件别名.方法名()

     注意:在elementui中所有组件都存在属性事件和方法

  • 属性:直接写在对应的组件标签上使用方式:属性名=属性值方式
  • 事件:直接使用vue绑定事件方式写在对应的组件标签上使用方式:@事件名=vue中事件处理函数
  • 方法:1.在对应组件标签上使用ref=组件别名;2.通过使用this.$refs.组件别名.方法名()进行调用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱学习de测试小白

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值