一、搭建项目以及初始化配置

vue create ts_vue_btn

这里使用了vue CLI3自定义选择的服务,我选择了ts、stylus等工具。然后创建完项目之后,进入项目。使用快捷命令code .进入Vs code编辑器(如果没有code .,需要将编辑器的bin文件目录地址放到环境变量的path中)。然后,我进入编辑器之后,进入设置工作区,随便设置一个参数,这里比如推荐设置字号,点下。这里是为了生成.vscode文件夹,里面有个json文件。


我们在开发项目的时候,项目文件夹内的文件很多,会有时影响视觉。那么这个文件就是设置什么文件隐藏,注意只是隐藏,而不是删除!下面是我自己写的,在Vue cli3生成的项目需要隐藏的文件参数。

{    "files.exclude": {        "**/.git": true,        "**/.svn": true,        "**/.hg": true,        "**/CVS": true,        "**/.DS_Store": true,        "**/README.md": true,        "**/node_modules":true,        "**/shims-tsx.d.ts": true,        "**/shims-vue.d.ts": true,        "**/.browserslistrc": true,        ".eslintrc.js": true,        "babel.config.js": true,        "package-lock.json": true,        ".gitignore": true,        "tsconfig.json": true    }}

以下就是所看到的文件目录,我把一些无关紧要的文件跟文件夹隐藏或者删除后所看到的。


文件解读(从上往下):

文件夹或文件 包含子文件夹或文件 含义
.vscode settings.json 隐藏文件设置
public index.html、favicon.ico 静态文件存放处
src components文件夹(存放组件)、App.vue、Home.vue、main.js 项目主要文件夹
package.json 项目依赖参数等

二、开发实践

下图为所需要创建的项目文件目录,这里我们开发一个Vue按钮组件。


如下图所示,这就是我们要用Typescript开发的组件。

开始编辑:
1、App.vue
<template>  <div id="app">   <Home>Home>   div>template><script lang="ts">import { Component, Vue } from 'vue-property-decorator';// 编写类样式组件所需要的一些类或者是装饰器import Home from "@/Home.vue"; // 引入页面组件// 这里我们需要使用Component装饰器,这个装饰器是注册组件用的,里面的参数是一个对象,内有一个components属性,值为引入的组件名@Component({  components:{    Home  }})export default class App extends Vue {}script><style lang="stylus">style>
2、UIBtn.vue
<template>    <button    class="ui-btn"    @click="onBtnclick('success!')"    :class="{    'ui-btn-xsmall':xsmall,    'ui-btn-small':small,    'ui-btn-large':large,    'ui-btn-xlarge':xlarge  }"  >    <slot>Buttonslot>  button>template><script lang="ts">import { Component, Vue, Emit, Prop } from "vue-property-decorator"; // 编写类样式组件所需要的一些类或者是装饰器@Componentexport default class UIBtn extends Vue {  @Prop(Boolean) private xsmall: boolean | undefined;  @Prop(Boolean) private small: boolean | undefined;  @Prop(Boolean) private large: boolean | undefined;  @Prop(Boolean) private xlarge: boolean | undefined;  // eslint-disable-next-line @typescript-eslint/no-empty-function  @Emit("click") private emitclick(x: string) {}  private mounted() {    console.log(this.large);  }  private onBtnclick(x: string) {    this.emitclick(x);  }}script><style scoped lang="stylus" >resize(a, b, c)  padding a b   font-size  c.ui-btn   resize(12px, 20px, 14px)  border 0 solid #000  border-radius 4px  outline none  font-weight 500;  letter-spacing 0.09em  background-color #409eff  color #fff  cursor pointer  user-select none  &:hover    filter brightness(120%)  &:active    filter brightness(80%)  &.ui-btn-xsmall     resize(5px, 15px, 14px)  &.ui-btn-small     resize(8px, 18px, 14px)  &.ui-btn-large     resize(14px, 22px, 14px)  &.ui-btn-xlarge     resize(16px, 24px, 14px)style>
3、Home.vue
<template>  <div class="home-con">      <div class="btn-group">           <UIBtn class="btn" @click="resize('xsmall')">超小UIBtn>           <UIBtn class="btn" @click="resize('small')">小UIBtn>           <UIBtn class="btn" @click="resize('normal')">正常UIBtn>           <UIBtn class="btn" @click="resize('large')">大UIBtn>           <UIBtn class="btn" @click="resize('xlarge')">超大UIBtn>      div>      <div class="btn-con">           <UIBtn @click='onClick'            :xlarge="xlarge"           :large="large"           :small="small"           :xsmall="xsmall"           >主要按钮UIBtn>      div>      <div class="btn-pro">            <UIBtn large >样式按钮UIBtn>      div>      div>template><script lang="ts">import { Component, Vue } from 'vue-property-decorator'; // 编写类样式组件所需要的一些类或者是装饰器import UIBtn from '@/components/UIBtn.vue';@Component({    components:{      UIBtn    }})export default class Home extends Vue {   // eslint-disable-next-line @typescript-eslint/no-inferrable-types   private xlarge: boolean = false;    // eslint-disable-next-line @typescript-eslint/no-inferrable-types   private large: boolean = false;    // eslint-disable-next-line @typescript-eslint/no-inferrable-types   private xsmall: boolean = false;    // eslint-disable-next-line @typescript-eslint/no-inferrable-types   private small: boolean = false;   private resize (name: string){       console.log(name)       switch (name) {           case 'xsmall':               this.xsmall=true;               this.small=false;               this.large=false;               this.xlarge=false;               break;           case 'small':               this.xsmall=false;               this.small=true;               this.large=false;               this.xlarge=false;               break;           case 'normal':               this.xsmall=false;               this.small=false;               this.large=false;               this.xlarge=false;               break;           case 'large':               this.xsmall=false;               this.small=false;               this.large=true;               this.xlarge=false;               break;           case 'xlarge':               this.xsmall=false;               this.small=false;               this.large=false;               this.xlarge=true;               break;       }   }   private onClick(x: string) {       console.log(x)    }}script><style lang="stylus" scoped>.btn-group    margin 50px 0.btn    margin 6px.btn-pro    margin-top 50px style>

vscode svn使用_使用Typescript封装Vue组件相关推荐

  1. 封装Vue组件的原则及技巧

    封装Vue组件的原则及技巧 Vue的组件系统 Vue组件的API主要包含三部分:prop.event.slot props表示组件接收的参数,最好用对象的写法,这样可以针对每个属性设置类型.默认值或自 ...

  2. 封装 vue 组件的过程记录

    在我们使用vue的开发过程中总会遇到这样的场景,封装自己的业务组件. 封装页面组件前要考虑几个问题: 1.该业务组件的使用场景 2.在什么条件下展示一些什么数据,数据类型是什么样的,及长度颜色等 3. ...

  3. Vue2组件封装 Vue组件封装

    写在前面 虽然是Vue2组件封装,主要的内容是记录一下我对封装组件的一些要点和我的看法 --原学习视频来源于b站黑马从0到1封装组件库 什么是组件 都说Vue是组件化开发,确实有道理,别说按钮输入框这 ...

  4. vue 移动端头像裁剪_vue头像上传裁剪组件_一个漂亮的Vue组件,用于图像裁剪和上传...

    vue头像上传裁剪组件 vue-image-crop-upload (vue-image-crop-upload) A beautiful vue component for image crop a ...

  5. 手把手教你封装 Vue 组件并使用 NPM 发布

    Vue 开发插件 我们可以先查看Vue的插件的开发规范 我们开发的之后期望的结果是支持 import.require 或者直接使用 script 标签的形式引入,就像这样: ps: 这里注意一下包的名 ...

  6. vue 构建根组件_构建迷你图Vue组件

    vue 构建根组件 Sparklines can be used to quickly visualize data variance. They are small and intuitive to ...

  7. vue3+TypeScript封装echarts5组件

    https://blog.csdn.net/qq_38330707/article/details/111497853 有用mark 等抽时间写个vue+TS+echarts5.0的组件文章 写个大概 ...

  8. vue避免重新渲染_详解强制Vue组件重新渲染的方法

    在某些情况下,我们必须强制Vue重新渲染组件,如果没有,那可能,你做的业务还不够负责,反正我是经常需要重新渲染组件,哈哈. 虽然Vue不会自动更新这种情况是相对比较少,但是知道如何在出现这个问题时修复 ...

  9. 简述封装vue组件的过程

    组件可以提升整个项目的开发效率,能够把页面抽象成多个相对独立的模块,解决 了我们传统项目开发:效率低.难维护.复用性等问题. 分析需求:确定业务需求,把页面中可以复用的结构,样式以及功能,单独抽离成一 ...

最新文章

  1. 代码攻击破坏设备,炸毁 27 吨发电机的背后
  2. hdu 2553 N皇后问题(深度递归搜索)
  3. 清华大学人工智能研究院成立大数据智能研究中心
  4. Java处理某些图片红色问题
  5. 跟我一起学.NetCore之.NetCore概述
  6. Linux的sort命令用法
  7. 【Excel】提取身份证信息
  8. 自检代码中trustmanager漏洞_Windows内核漏洞利用教程
  9. win10电脑浏览器哪个好_电脑WinXP、Win7和Win10,哪个操作系统最好用?
  10. 手把手教你做酷炫的数据可视化大屏,零基础的你仅需6步
  11. 4图纸 rust_安诺伊模具丨机加工图纸有英语看不懂?不怕!史上最全翻译都在这...
  12. java blowfish ecb,node.js – 使用nodejs crypto和php的mcrypt解密blowfish-ecb
  13. qt设置背景图片变黑色_PS软件如何快速制作一个黑色创意海报
  14. 矩阵范数与向量范数的公式及其理解
  15. Luogu3387【模板】缩点(Kosaraju)
  16. 网络与信息安全基础知识专栏
  17. java获取当前周数_java获取周数的方法
  18. 关于quicktime
  19. mysql里一个中文多少个字节_mysql里中文占多少个字节?
  20. 什么软件能测试你的cp是谁,叶罗丽测试:当你来到魔法世界,测你最有可能拆散哪对CP?...

热门文章

  1. 这个东西可以温暖你想打BUG的心......
  2. “Scrum 敏捷开发都是骗人的!”
  3. 被“遗弃”的互联网老年人 | 畅言
  4. 移动开发或将被颠覆?
  5. 2018 腾讯功能游戏开发者赛事火热开启
  6. oracle u4e00 u9fa5,Oracle 判断汉字 [\u4e00-\u9fa5]
  7. mysql主从同步触发器_Mysql 主从复制触发器问题
  8. matlab检测串口数据帧头,用matlab从串口读入数据产生图像进行分析遇到的问题,求大虾帮助!...
  9. ie 传递给系统调用的数据区域太小。_RFID银行资产管理系统,智能,简便,易操作...
  10. 信签纸有虚线怎么写_edm邮件营销,专注解决你的开发信难题