V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
sox
V2EX  ›  分享创造

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

  •  
  •   sox ·
    egoist · 2017-03-20 22:45:24 +08:00 · 6540 次点击
    这是一个创建于 2592 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 (可以在线编辑运行)

    7 条回复    2017-03-21 16:39:08 +08:00
    Alexisused
        1
    Alexisused  
       2017-03-21 07:20:34 +08:00 via Android
    闲了试试
    zaishanfeng
        2
    zaishanfeng  
       2017-03-21 07:41:18 +08:00
    怎么配合 nginx
    nicoljiang
        3
    nicoljiang  
       2017-03-21 10:23:27 +08:00
    它的意义是什么啊?
    sox
        4
    sox  
    OP
       2017-03-21 13:31:54 +08:00
    @zaishanfeng 和普通 node.js server 一样
    yyy
        5
    yyy  
       2017-03-21 14:25:54 +08:00
    能用 Koa 吗?
    sox
        6
    sox  
    OP
       2017-03-21 16:32:58 +08:00
    yyy
        7
    yyy  
       2017-03-21 16:39:08 +08:00
    @sox #5 👍赞,献上 star 和膝盖。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3277 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 14:13 · PVG 22:13 · LAX 07:13 · JFK 10:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.