vue-cli3.0以上 + typeScript 教程学习指导(一) 入门typeScript

之前在简单的学习了ts后 一直想将它 与vue结合起来 一直没有,对此就开始打算以文章的形式一步一步来  从简单入手。

单纯的typeScript如何教程:https://ts.xcatliu.com/

我将写一系列的文章 来和大家一起进步,我的所有系列文章 会涉及到

      1,搭建  跑起来

      2 数据处理,指令v-if v-for  事件处理,生命周期

      3 计算属性 watch

      4 父子传值

       5 vueX的使用

       6 做一个登录项目

        7 做一个登录加下订单的项目

所有系列文章地址https://blog.csdn.net/www_share8/category_9877844.html

现在我们就先来 搭建项目吧

vue create tslearn 

然后选择自定义

然后等待下载就可以

然后运行起来就可以了  到这一步就进步算完成 我们的第一系列的目标了,但为了后续的系列文章 这里需要添加一些东西和改建一些项目。

想来添加 elment-ui  https://element.eleme.cn/#/zh-CN/component/input,

vue add element

选择如上 选择 语言 zh-cn 我选择全部安装

看到 button 按钮 就知道  我们安装 完成了  接下来做一些改动  删除一些页面 和规整一下路由,暂时不想涉及父子页面

App.vue

<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>


export default {
  name: 'app'
}
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

router index

import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import Index from '../components/HelloWorld.vue'

Vue.use(VueRouter)

const routes: RouteConfig[] = [
  {
    path: '/',
    name: 'Index',
    component: Index,
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/About.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

export default router

将HelloWorld.vue 变成如下

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>

  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";

@Component
export default class HelloWorld extends Vue {
  private msg: string = "测试";
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

配置一下  tsline.json  作用和eslint差不多

{
  "defaultSeverity": "warning",
  "extends": [
    "tslint:recommended"
  ],
  "linterOptions": {
    "exclude": [
      "node_modules/**",
      "tests/**"
    ]
  },
  "rules": {
    "trailing-comma": [
      true,
      {
        "singleline": "never",
        "multiline": {
          "objects": "ignore",
          "arrays": "always",
          "functions": "never",
          "typeLiterals": "ignore"
        }
      }
    ],
    "quotemark": [
      false,
      "single"
    ],
    "indent": [
      true,
      "spaces",
      2
    ],
    "interface-name": false,
    "ordered-imports": false,
    "object-literal-sort-keys": false,
    "no-consecutive-blank-lines": false,
    "semicolon": [
      false,
      "always",
      "ignore-interfaces"
    ],
    "member-access": false,
    "no-console": false,
    "max-line-length": [
      false
    ],
    "no-parameter-properties": false,
    "no-debugger": false,
    "no-unused-expression": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "triple-equals": true,
    "no-empty": [
      true,
      "allow-empty-catch"
    ],
    "no-unnecessary-type-assertion": true,
    "return-undefined": true,
    "no-parameter-reassignment": true,
    "curly": [
      true,
      "ignore-same-line"
    ],
    "no-construct": true,
    "no-duplicate-super": true,
    "no-duplicate-switch-case": true,
    "no-duplicate-variable": [
      true,
      "check-parameters"
    ],
    "no-return-await": true,
    "no-sparse-arrays": true,
    "no-switch-case-fall-through": true,
    "prefer-object-spread": true,
    "use-isnan": true,
    "cyclomatic-complexity": [
      true,
      20
    ],
    "no-duplicate-imports": true,
    "encoding": true,
    "no-unnecessary-initializer": true,
    "number-literal-format": true,
    "one-line": true,
    "space-before-function-paren": [
      true,
      "asyncArrow"
    ],
    "no-unsafe-finally": true
  }
}

最终页面就完成了

至此 我们就完成了 vue +typeScript的搭建工作,也是所有代码的 基础框架搭建好了。

接下来 看我的  第二系列  将和大家一起探讨 数据 和事件

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值