vue中路由在新的标签页打开

1
2
3
4
5
6
let routeData = this.$router.resolve({
name: 'commercialPreview',
query: {cylType: this.$route.query.cylType},
params: { id: this.id }
})
window.open(routeData.href, '_blank')

vue的计算属性computed

vue的计算属性用于简单运算,在模版中太多的逻辑会难以维护,例如:

1
2
3
<div id="example">
{{ message.split('').reverse().join('') }}
</div>

这个地方逻辑是字符串反转,如果多次使用会造成不好维护的现象,而且逻辑代码写在模版里可读性并不是很好。

新建koa2项目

1.npm install -g koa-generator

2.koa2 项目名称,如果需要ejs引擎koa2 -e 项目名称

3.cd 项目名称

4.npm install

5.npm install –update-binary

6.npm run dev

小知识点:对于start和test可以使用npm,对于dev和prd必须使用npm run来启动

koa中间件

1
2
3
4
5
6
7
8
9
10
11
12
13
function pv(ctx){
global.console.log(ctx.path);
}
module.exports=function(){
return async function(ctx,next){
pv(ctx);
await next(); //next是继续执行下面的中间件,如果不写会直接跳出,不会继续执行
}
}

// app.js文件
const pv = require('./middleware/koa-pv');
app.use(pv())

koa路由接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const router = require('koa-router')()
//返回一个页面
router.get('/', async (ctx, next) => {
global.console.log('index11111');
await ctx.render('index', { //render返回一个页面
title: 'Hello Koa 2!'
})
})
//直接返回数据的用body,json数据
router.get('/json', async (ctx, next) => {
ctx.body = {
title: 'koa2 json'
}
})
//在不同页面为了区分接口,我们可以在加个前缀/user
router.prefix('/users')
module.exports = router

// app.js文件
app.use(index.routes(), index.allowedMethods())
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×