vue create ts_vue_btn
複製代碼
這裏使用了vue CLI3
自定義選擇的服務,我選擇了ts、stylus
等工具。而後建立完項目以後,進入項目。使用快捷命令code .
進入Vs code編輯器(若是沒有code .
,須要將編輯器的bin文件目錄地址放到環境變量的path
中)。而後,我進入編輯器以後,進入設置工做區,隨便設置一個參數,這裏好比推薦設置字號,點下。這裏是爲了生成.vscode
文件夾,裏面有個json
文件。 javascript
咱們在開發項目的時候,項目文件夾內的文件不少,會有時影響視覺。那麼這個文件就是設置什麼文件隱藏,注意只是隱藏,而不是刪除!下面是我本身寫的,在Vue cli3生成的項目須要隱藏的文件參數。css
{
"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
}
}
複製代碼
如下就是所看到的文件目錄,我把一些可有可無的文件跟文件夾隱藏或者刪除後所看到的。 html
文件夾或文件 | 包含子文件夾或文件 | 含義 |
---|---|---|
.vscode | settings.json | 隱藏文件設置 |
public | index.html、favicon.ico | 靜態文件存放處 |
src | components文件夾(存放組件)、App.vue、Home.vue、main.js | 項目主要文件夾 |
package.json | 無 | 項目依賴參數等 |
下圖爲所須要建立的項目文件目錄,這裏咱們開發一個Vue按鈕組件。 vue
Typescript
開發的組件。
<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>
複製代碼
<template>
<!-- v-on="$listeners" 能夠使用,在本類再也不監聽,在其餘地方監聽,能夠不用$emit(),可是咱們這裏不用它 -->
<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>Button</slot>
</button>
</template>
<script lang="ts"> import { Component, Vue, Emit, Prop } from "vue-property-decorator"; // 編寫類樣式組件所須要的一些類或者是裝飾器 @Component export 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>
複製代碼
<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>
複製代碼