17、vue

说明:

vue3.0搭建的项目,不过没有引入ts,后来需要用到一个插件是用ts写的,所以vue要用到ts。。。

一、安装typescript及loader

npm install typescript ts-loader --save-dev

image

二、安装vue-property-decorator

npm install vue-property-decorator --save-dev

image

三、配置vue.config.js

1module.exports = { 2 configureWebpack: { 3 resolve: { extensions: [".ts", ".tsx", ".js", ".json"] }, 4 module: { 5 rules: [ 6 { 7 test: /\.tsx?$/, 8 loader: 'ts-loader', 9 exclude: /node_modules/, 10 options: { 11 appendTsSuffixTo: [/\.vue$/], 12 } 13 } 14 ] 15 } 16 } 17} 18 19 20var path = require('path'); 21module.exports = { 22 outputDir:'vuecli3', 23 publicPath: './', 24 devServer: { 25 // 设置主机地址 26 host: 'localhost', 27 // 设置默认端口 28 // port: '8080', 29 // 打开浏览器 30 open: true, 31 port: 9000, 32 // 设置代理 33 // proxy: { 34 // '/api': { 35 // target: 'http://localhost:8081', 36 // pathRewrite: { 37 // '^/api': '/mock' 38 // } 39 // } 40 // } 41 }, 42 configureWebpack: { 43 resolve: { extensions: [".ts", ".tsx", ".js", ".json"] }, 44 module: { 45 rules: [ 46 { 47 test: /\.tsx?$/, 48 loader: 'ts-loader', 49 exclude: /node_modules/, 50 options: { 51 appendTsSuffixTo: [/\.vue$/], 52 } 53 } 54 ] 55 } 56 } 57}

image

四、新建tsconfig.json放在项目根目录

1{ 2 "compilerOptions": { 3 "target": "es5", 4 "module": "commonjs", 5 "strict": true, 6 "strictNullChecks": true, 7 "esModuleInterop": true, 8 "experimentalDecorators": true 9 } 10} 11

image

五、在src目录下新建vue-shim.d.ts文件

不加此文件会报错。。

image

1declare module "*.vue" { 2 import Vue from "vue"; 3 export default Vue; 4}

六、运行测试

1<template> 2 <div> 3 <el-button type="primary" @click="msgBtn">{{msg}}</el-button> 4 <el-card shadow="always"> 5 {{test}} 6 </el-card> 7 </div> 8</template> 9<script lang='ts'> 10import { Component, Vue } from "vue-property-decorator"; 11 12export default Vue.extend({ 13 components: { 14 // TableCom 15 }, 16 data() { 17 return { 18 msg:'typescript' 19 }; 20 }, 21 created(){ 22 console.log('created',this.msg) 23 }, 24 mounted() { 25 console.log('mounted') 26 }, 27 computed:{ 28 // test: { 29 // // 需要标注有 `this` 参与运算的返回值类型 30 // get(): string { 31 // return this.msg 32 // }, 33 // set(val: string) { 34 // this.msg = val 35 // } 36 // } 37 test(): any { 38 return this.msg 39 } 40 }, 41 watch:{ 42 msg(val:any){ 43 console.log('watch',val) 44 } 45 }, 46 methods:{ 47 msgBtn(ev:any){ 48 this.msg = "点击了typescript" 49 console.log('点击事件',ev) 50 } 51 } 52}) 53 54</script>

image

image

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )