版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
npmnpmikoa-bodyparserkoa-router@nuxtjs/axios-npmnpmi--modules:modules:exportexportconstactions{nuxtServerInit({commit},{app{consttoken=app.$ if(token){console.log("nuxtServerInit:token:"+token);commit("user/init",token);}}exportexportdefaultfunction({$axios,store})$axios.onRequest(config=>if(store.state.user.token)config.headers.Authorization='Bearer}return}npmnpmrunbuildnpmstart////constKoa=constbodyparser=require("koa-constrouter=require("koa-router")({prefix:"/api"constapp=new//app.keys=["somesecret","anotherconstgoods={id:1,text:"Web全栈架构师",price:1000{id:2,text:"Python架构师",price:1000///api/goodsrouter.get("/goods",ctx=>{ctx.body=ok:router.get("/detail",ctx{ctx.body={ok:1,data:goods.find(good=>good.id==router.post("/login",ctx{constuser=if(user.username==="jerry"&&user.password==="123")//将tokenconsttoken='amocktoken';ctx.s.set('token',token);ctx.body={ok:1,token};}elsectx.body={ok:0}//constKoa=constconsola=const{Nuxt,Builder}=constapp=new//ImportandSetNuxt.jsletconfig=require("../nuxt.config.js");config.dev=!(app.env==="production");asyncfunctionstart()//Instantiateconstnuxt=newconsthost=process.env.HOST||"",port=process.env.PORT||3000}=//Buildindevelopmentif(config.dev){constconstbuilder=newBuilder(nuxt);awaitbuilder.build();}elseawait}app.use(ctx{ctx.status=ctx.respond=false;//BypassKoa'sbuilt-inresponsectx.req.ctx=ctx;//Thismightbeusefullateron,e.g.innuxtServerInitorwithnuxt-stashnuxt.render(ctx.req,app.listen(port,host);message:`Serverlisteningonhttp://${host}:${port}`,badge:true}axiosaxios:::"/api":" "scripts":"scripts":"generate":"cross-envPORT=80nuxt}npmnpmrunserverserverserver_namelocation/rootC:\\Users\\yt037\\Desktop\\kaikeba\\projects\\nuxt-index}location^~/api/};#注意路径后边不要加}letletname="xxlettitle:string开课吧类型注解name=2;//错误title=4;//letnames:names=['Tom'];//或letfoo:any=foo=//anyletlist:any[]=[1,true,list[1]=//functionfunction{returno,':string):;}functionwarnUser():void{alert("Thisismywarningmessage");////此处name和age////functiono(name:string,age:number=20,addr?:string):{return你好:name}//参数数量或者类型或者返回类型不同// functioninfo(a:{name:string}):string;functioninfo(a:string):object;functioninfo(a:{name:string}|string):{if(typeofa==="object"){return;}elsereturn{name:a}}console.log(info({name:"tom"类Class,面向对象classShape{//area:constructor(protectedcolor:string,privatewidth:number,privateheight:number){//this.area=width*heightthis.color=color}存取getgetarea()returnthis.width*}shoutout()return"I'm"+this.color+"withanareaof"+this.area+"cmsquared."}}classSquareextendsShapeconstructor(color:string,side:{super(color,side,side)}//覆盖shoutoutreturn"我是"+this.color+"面积是"+this.area+"平方厘米}}constsquare=newSquare('blue',2){firstName:string;lastName:string; ostring;//}classGreeter constructor(publicfirstName='',publiclastName=''){} return o,'+this.firstName+''+}}//面向接口编程functiongreeting({ }//constuser={firstName:'Jane',lastName:'User'};constusernewGreeter('Jane''User'创建对象实例interface{ok:0|data:}functiongetData<T>():{constdata:any[]={id:1,name:"类型注解",version:"2.0"{id:2,name:"编译型语言",version:"1.0"return{ok:1,data}this.features=装饰类装饰exportdefault属性装饰oextendsVue@Prop({required:true,type:String})privatemsg!:函数装饰@Watch("features",{deep:true})onRouteChange(val:string,oldVal:any){console.log(val,}函数装饰privateaddFeature(event:{constfeature=name:event.target.value,id:this.features.length+1,versionversion:event.target.value=feature;return}} functionfunctionadd(num1,{returnnum1+}testdescribe('Kaikeba',()=>//测试用例testcaseit('测试add函数'{//断言assertexpect(add(1,expect(add(1,expect(add(-2,npmnpmrun测试Vue <span>{{message<button@click="changeMsg">点击 export{data(){return{message:'vue-}createdthis.message'开课this.message='按钮点击}}}////导入Vue.jsimportVuefrom pfrom p',()=>it('由created生命周期',()=> //it('初始data是vue-text',()=>//检查data //检查dataconstataitit('mount之后测data是开课吧',()=>constvm=newVue( importimport{mount}from'@vue/test-it("按钮点击后",()=>constwrapper=测试html//等效的方式{"collectCoverageFrom":module.exportsmodule.exports="collectCoverage":true,"collectCoverageFrom":["src/**/*.{js,vue}"]}在此执行npmruntest:unitVueTestUtils使用指南E2E运行E2Enpmnpmrundescribe('端到端测试,抢测试人员的饭碗'{it('先 一下',()=>{//cy.contains('h1', etoYourVue.jscy.contains('span''开课吧<div<div<imga
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB65T8019-2024回弹法检测高强混凝土抗压强度技术标准(公开版)
- 智能制造数字孪生应用标准(2025版)
- 工器具消毒管理制度
- 沥青施工烫伤中毒应急演练脚本
- 细胞生物学试题库及参考答案
- 勘察设计人员准则
- 精装修火灾应急演练脚本
- 2026年辣椒采购协议(调料厂)
- 2026年跨境电商数据使用合同协议
- 科技创新经费使用监督制度
- 《锂离子电池产品技术规范 电池护照》
- 《项目管理培训课件》课件
- 四川省成都市2023年中考道德与法治真题试卷(含答案)
- 中华护理学会团体标准-气管切开非机械通气患者气道护理
- 市第二中学学生餐厅公寓楼建设项目项目建议书
- JTS-131-2012水运工程测量规范
- DZ∕T0312-2018 非金属矿行业绿色矿山建设规范(正式版)
- 危大工程安全监理实施细则
- 等效声级计算表
- AS9120B程序文件一整套
- 门脉高压性消化道出血的介入治疗
评论
0/150
提交评论