vue模仿twitter寫一個自己的博客——登錄彈窗

主要是要寫input組件,以及實現(xiàn)點擊區(qū)域外部的區(qū)域,關閉該區(qū)域,用css畫三角形。將登錄區(qū)域絕對定位到header。具體的細節(jié)可以看源碼
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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 基于Vue的一些資料 內容 UI組件 開發(fā)框架 實用庫 服務端 輔助工具 應用實例 Demo示例 element★...
    嘗了又嘗閱讀 1,284評論 0 1
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    柴東啊閱讀 15,962評論 2 140
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    你猜_3214閱讀 11,338評論 0 118
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    王喂馬_閱讀 6,585評論 1 77
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    小姜先森o0O閱讀 10,114評論 0 72

友情鏈接更多精彩內容