首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Vue.js 2.3.0 Release 正式发布. sync 特性回归

Vue.js 2.3.0 Release 正式发布. sync 特性回归

作者头像
CRPER
发布于 2024-02-14 02:21:09
发布于 2024-02-14 02:21:09
19100
代码可运行
举报
文章被收录于专栏:CRPER折腾记CRPER折腾记
运行总次数:0
代码可运行

🚀 New

Server-Side Rendering Improvements

Note: We have created a brand-new standalone guide for server-side rendering in Vue, it's a recommended read for all users. Also, the HackerNews demo has been updated to reflect the latest best practices.

Now uses the data-server-rendered attribute to indicate server-rendered markup, making the output valid HTML.

template option now supports simple interpolation using the render context. This allows the template to be dynamic based on the data attached to the context by rendered components.

See docs for more details.

New bundleRenderer option: runInNewContext

Defaults to true, which preserves the original behavior.

When set to false, the renderer will no longer re-execute the entire bundle in a new vm context for each render. Instead, only the function exported by the bundle will be called again. This greatly improves performance, but requires some changes in source code structure.

See docs for more details.

New bundleRenderer option: clientManifest

By passing the bundleRender a client webpack build manifest generated by vue-server-renderer/client-plugin, the renderer can infer the proper build assets that need to be preloaded (e.g. code-split async chunks, images, and fonts). When using together with the template option, <link rel="preload/prefetch"> and appropriate <script> tags will be injected automatically.

See docs for more details.

vue-ssr-webpack-plugin is now deprecated, instead, it is now part of vue-server-renderer. It now also exposes two plugins - one for the server build and one for the client build.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
var VueSSRClientPlugin = require('vue-server-renderer/client-plugin')

See docs for more details.

Async Component Improvements

Async component factories can now return an object of the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
const AsyncComp = () => ({
  // The component to load. Should be a Promise
  component: import('./MyComp.vue'),
  // A component to use while the async component is loading
  loading: LoadingComp,
  // A component to use if the load fails
  error: ErrorComp,
  // Delay before showing the loading component. Defaults to 200ms.
  delay: 200,
  // The error component will be displayed if a timeout is provided and exceeded.
  timeout: 3000
})

Note that when used as a route component in vue-router, these properties will be ignored because async components are resolved upfront before the route navigation happens. You also need to update vue-router to 2.4.0+ if you wish to use the new syntax for route components.

Functional Component Improvements

Functional components can now omit the props option. All attributes will be automatically extracted and exposed as camelized props on context.props.

Note when the props option is provided, it will retain the old behavior - i.e. only explicitly declared props will be extracted.

v-on listeners attached to a functional component will be exposed as context.listeners. This is simply an alias to context.data.on.

Combined with the props change, functional components usage can be much cleaner:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
const MyComp = {
  functional: true,
  render (h, { props, listeners }) {
    return h('div', {
      on: {
        click: listeners.click // proxy click listener
      }
    }, [
      props.msg // auto extracted props
    ])
  )
}

Functional components now also support the inject option. Injected properties are exposed as context.injections. (@Kingwl via #5204)

Other Improvements

.sync is back! However it now is simply syntax sugar that expands into a prop + listener pair, similar to v-model.

The following

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<comp :foo.sync="bar"></comp>

is expanded into:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<comp :foo="bar" @update:foo="val => bar = val"></comp>

For the child component to update foo's value, it needs to explicitly emit an event instead of mutating the prop:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
this.$emit('update:foo', newValue)

Warnings now include component hierarchy traces.

Vue.config.errorHandler now also handles error thrown inside custom directive hooks (@xijiongbo via #5324)

Vue.config.errorHandler now also handles error thrown in nextTick callbacks.

New v-on modifier: .passive - adds the event listener with { passive: true }. (@Kingwl via #5132)

Props validation now supports type: Symbol.

style bindings now support using an Array to provide multiple (prefixed) values to a property, so the following would be possible (@fnlctrl via #5460):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<div :style="{ display: ["-webkit-box", "-ms-flexbox", "flex"] }">

An extended component constructor can now also be used as a mixin. (@ktsn via #5448)

🐛 Fixed

  • #5238, #5387 fix v-model not syncing for autocomplete / switching focus before confirming composition
  • #5318 fix style diffing on cached/slot elements
  • #5346 fix keep-alive cache incorrectly pruned with transition mode="out-in"
  • #5361 fix Symbol check error in Node 4.x
  • #5394 fix duplicate attribute warning when using class and :class together in Edge
  • #5398 fix v-model checkbox binding with Array index (@posva via #5402)
  • #5464 fix incorrect compiler warning for $delete usage in templates
  • #5480 allow slot names to be number 0 (@posva via #5481)
  • #5526 fix text inside <script type="x/template"> being unnecessarily decoded
  • vue-class-component#87 fix base class lifecycle hook dropped when constructor options are modified before applying global mixin
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-02-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Vue.js 2.5新特性介绍
TypeScript TypeScript是一种由微软开发的自由和开源的编程语言。它是JavaScript的一个超集,而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程。2012年十月份,微软发布了首个公开版本的TypeScript,在2013年6月19日,微软发布了TypeScript 0.9的正式版本,到目前为止,TypeScript已发展到2.x版本,相关资料可以查看W3C TypeScript入门 安装TypeScript 安装TypeScript主要有两种方式: 通过npm方式安装(N
xiangzhihong
2018/02/06
2.1K0
Vue.js 2.5新特性介绍
Vue 2.3、2.4 知识点小结
新增.passive 修饰符 (demo1) ; .passive 修饰符表示事件永远不会调用 preventDefault() ,主要为解决滚动和触摸事件的卡顿而出现,关于 passive 更多信息请移步 MDN 。
三毛
2024/01/28
2240
带你五步学会Vue SSR
SSR大家肯定都不陌生,通过服务端渲染,可以优化SEO抓取,提升首页加载速度等,我在学习SSR的时候,看过很多文章,有些对我有很大的启发作用,有些就只是照搬官网文档。通过几天的学习,我对SSR有了一些了解,也从头开始完整的配置出了SSR的开发环境,所以想通过这篇文章,总结一些经验,同时希望能够对学习SSR的朋友起到一点帮助。
leocoder
2024/02/01
4760
带你五步学会Vue SSR
必会vue面试题总结
组件化是 Vue, React 等这些框架的一个核心思想,通过把页面拆成一个个高内聚、低耦合的组件,可以极大程度提高我们的代码复用度,同时也使得项目更加易于维护。所以,本文就来分析下组件的渲染流程。我们通过下面这个例子来进行分析:
bb_xiaxia1998
2022/12/16
2760
实用!最新的几个 Vue 3 重要特性提案
在几天前开启的 SFC Improvements #182 中,yyx990803 提交了 3 个改进开发者体验的征求意见稿。
江米小枣
2020/07/09
9490
vue2.6.11源码结构
李才哥
2023/06/28
1700
SSR再好,也要有优雅降级策略哟~
我所在的部门采用得基于vue的Nuxt框架来实现ssr同构渲染,但是Nuxt并未提供相应的降级策略。当node服务端请求出现偶发性错误(非接口服务挂掉),本来应该在首屏渲染的模块会因无数据而显示空白,双十一等高流量情况下,出现人肉“运维”的无奈,想象一下其他小伙伴陪着对象,吃着火锅、唱着歌,你在电脑前抱着忐忑不安的心情盯着监控系统....我们需要一个降级方案以备不时之需。
胡哥有话说
2020/11/03
5.1K0
SSR再好,也要有优雅降级策略哟~
面试官:什么是虚拟DOM?如何实现一个虚拟DOM?
虚拟 DOM (Virtual DOM )这个概念相信大家都不陌生,从 React 到 Vue ,虚拟 DOM 为这两个框架都带来了跨平台的能力(React-Native 和 Weex)
@超人
2021/02/26
2.4K0
面试官:什么是虚拟DOM?如何实现一个虚拟DOM?
[咖聊] 从 render 到 VNode
由于 _render 和 _update 的过程还是挺复杂的,分成两期。这一期我们就先聊聊 _render 过程。
码农小余
2022/06/16
1.2K0
[咖聊] 从 render 到 VNode
10个简单的技巧让你的 vue.js 代码更优雅
作为深度代码洁癖,我们都希望能写出简单高效的代码,让我们的代码看起来更加优雅,让我们抛弃繁杂的代码,一起开启简单的旅程~~
王小婷
2020/11/10
1.2K0
Vue 2.3、2.4 知识点小结
2.3 参考 github.com/vuejs/vue/r… 2.4 参考 github.com/vuejs/vue/r… 实例 demo 地址:github.com/jkchao/vue-…
三毛
2018/08/30
7370
Vue 2.3、2.4 知识点小结
探讨一下 To C 营销页面服务端渲染的必要性及其原理
最近无论是在公司还是自己研究的项目,都一直在搞 H5 页面服务端渲染方面的探索,因此本文来探讨一下服务端渲染的必要性以及其背后的原理。
前端森林
2022/01/24
1.4K0
探讨一下 To C 营销页面服务端渲染的必要性及其原理
让vue-cli初始化后的项目集成支持SSR
当前 SPA 架构流行的趋势如日中天,但在 SEO 方面好像一直是个痛点,所以众多流行的 mv* 等框架也为此痛点提出了解决方案。 vue 官方提供了快速构建项目的工具 vue-cli,其方便快捷性众所周知。本文章来分享一下使用vue cli构建项目后如何集成 SSR(server side render 服务器端渲染),本文主要说明使用两种方式来实现SSR的效果。
奋飛
2019/08/15
2.4K1
立等可取的 Vue + Typescript 函数式组件实战
不同于面向对象编程(OOP)中通过抽象出各种对象并注重其间的解耦问题等,函数式编程(FP) 聚焦最小的单项操作,将复杂任务变成一次次 f(x) = y 式的函数运算叠加。函数是 FP 中的一等公民(First-class object),可以被当成函数参数或被函数返回;同时,这些函数应该不依赖或影响外部状态,这意味着对于给定的输入,将产生相同的输出。
江米小枣
2020/11/04
2.5K0
立等可取的 Vue + Typescript 函数式组件实战
微信开放文档是个病,得治!
以前,微信开放文档是使用文档界的老大哥— gitbook。用它搭建文档其实并不需要耗费多长时间,主要在于界面维护和自定义主题。Jquery 则是里面主要用来做前端 UI 界面的工具,前端er 应该都清楚 Jquery 有个代号:编程一时爽,重写火葬场。具体是什么意思呢?以前前端的思维模式是根据 事件驱动,导致,一整个项目下来差不多全部都是围绕着 addEventListener 写。而最新的前端框架提供的思维改变为 数据驱动,视图层分离,有点类似 Android/IOS 的组件开发模式 + 生命周期 Hook 类似。
villainhr
2019/07/30
1.5K0
Vue2剥丝抽茧-虚拟 dom 之自定义组件
虚拟dom 中我们按照 vue 本身的目录接口进行了整理,通过 render 函数返回虚拟 dom 最终完成页面的渲染。这篇文章,我们来实现自定义组件。
windliang
2022/08/20
7210
Vue.js 服务端渲染业务入门实践
iKcamp
2018/01/04
1.9K0
进阶| Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(下篇)
前端爱好者的知识盛宴 导语 这是Vue多页面框架系列文章的第二篇,上一篇中,我们尝试从webpack-simple原型项目改造为一个多页面的Vue项目。而这里,我们继续往前,尝试把Vue多页面改造为Nodejs直出。由于步骤较多,所以本文片幅较长。 上一篇:纯前端Vue多页面改造 本文源代码: https://github.com/kenkozheng/HTML5_research/tree/master/Vue-SSR-Multipages-Webpack3 正文 1 认识原理 稍微详细的信息,大家可以
用户1097444
2022/06/29
1.1K0
进阶| Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(下篇)
Vue.js 2 深入理解
含了父作用域中不作为 prop 被识别(且获取)的特性绑定(class 和 style 除外)
Cellinlab
2023/05/17
1.2K0
Vue.js 2 深入理解
vue源码分析-组件
Vue作为单页面应用遇到最棘手的问题是首屏加载时间的问题,单页面应用会把页面脚本打包成一个文件,这个文件包含着所有业务和非业务的代码,而脚本文件过大也是造成首页渲染速度缓慢的原因。因此作为首屏性能优化的课题,最常用的处理方法是对文件的拆分和代码的分离。按需加载的概念也是在这个前提下引入的。我们往往会把一些非首屏的组件设计成异步组件,部分不影响初次视觉体验的组件也可以设计为异步组件。这个思想就是按需加载。通俗点理解,按需加载的思想让应用在需要使用某个组件时才去请求加载组件代码。我们借助webpack打包后的结果会更加直观。
yyzzabc123
2022/10/17
6630
相关推荐
Vue.js 2.5新特性介绍
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档