vue模仿twitter写一个自己的博客——登录弹窗

主要是要写input组件,以及实现点击区域外部的区域,关闭该区域,用css画三角形。将登录区域绝对定位到header。具体的细节可以看源码
BlogInput.vue

<template>
  <input
    :type="type"
    :value="value"
    ref="blogInput"
    :placeholder="placeholder"
    @input="$emit('input',$event.target.value)"
  />
</template>
<script lang='ts'>
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
@Component({
  components: {}
})
export default class extends Vue {
  @Prop()
  private value!: string;
  @Prop()
  private placeholder!: string;
  @Prop()
  private type!: string;
  @Prop()
  private height!: string;
  @Prop()
  private width!: string;
  @Prop()
  private fontSize!: string;
  private mounted() {
    if (this.height) {
      if (!isNaN(Number(this.height))) {
        const obj = this.$refs.blogInput as HTMLElement;
        obj.style.height = this.height + "px";
      }
    }
    if (this.fontSize) {
      if (!isNaN(Number(this.fontSize))) {
        const obj = this.$refs.blogInput as HTMLElement;
        obj.style.fontSize = this.fontSize + "px";
      }
    }
    if (this.width) {
      if (this.width.endsWith("%")) {
        const temp = this.width.substring(0, this.width.length - 1);
        if (!isNaN(Number(temp))) {
          const obj = this.$refs.blogInput as HTMLElement;
          obj.style.width = temp + "%";
        }
      }
      if (!isNaN(Number(this.width))) {
        const obj = this.$refs.blogInput as HTMLElement;
        obj.style.width = this.width + "px";
      }
    }
  }
}
</script>
<style scoped lang="scss">
input {
  height: 27px;
  font-size: 14px;
  width: 230px;
  border-radius: 2px;
  border: 1px solid #cccccc;
  text-indent: 5px;
}
input:focus {
  border: 1.3px solid $boder-color;
  outline: none;
}
</style>

效果展示

在这里插入图片描述

项目地址

https://github.com/pppercyWang/twitter-blog-vue

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 基于Vue的一些资料 内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 element★...
    尝了又尝阅读 1,171评论 0 1
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    柴东啊阅读 15,876评论 2 140
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    你猜_3214阅读 11,131评论 0 118
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    王喂马_阅读 6,473评论 1 77
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    小姜先森o0O阅读 9,591评论 0 72