Vue 服务器端渲染从未这么简单

2017-03-20 22:45:24 +08:00
 sox

unvue 是基于 vue-router 的 Vue.js 应用同构 (SSR) 渲染框架, Vue 2.2 和最新的 vue-server-renderer 已经让 SSR 十分简单了,更进一步就是减少 boilerplate 代码和优化开发体验,而这就是 unvue 做的。和 Next.js/Nuxt.js 不同, unvue 不要求你有固定的目录结构,和普通的 webpack 项目没多大区别,想怎么放都行,只要在 src/index.js export 一个 router 就行了:

// your vue router instance
import router from './router'

export { router }

然后在你的项目里执行:

yarn add unvue
yarn unvue -- dev

打开 http://localhost:3000 就是一个完善的服务器端渲染的网站


项目: https://github.com/egoist/unvue

Demo: http://magnificent-heaven.glitch.me/ (妹子图)

Demo 代码: https://glitch.com/edit/#!/join/3768925c-57df-41cb-8b2b-57afc8789beb (可以在线编辑运行)

6569 次点击
所在节点    分享创造
7 条回复
Alexisused
2017-03-21 07:20:34 +08:00
闲了试试
zaishanfeng
2017-03-21 07:41:18 +08:00
怎么配合 nginx
nicoljiang
2017-03-21 10:23:27 +08:00
它的意义是什么啊?
sox
2017-03-21 13:31:54 +08:00
@zaishanfeng 和普通 node.js server 一样
yyy
2017-03-21 14:25:54 +08:00
能用 Koa 吗?
sox
2017-03-21 16:32:58 +08:00
yyy
2017-03-21 16:39:08 +08:00
@sox #5 👍赞,献上 star 和膝盖。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/348970

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX