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

简介: 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.


原文链接: github.com

🚀 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.


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:
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:


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


<comp :foo.sync="bar"></comp>


  • is expanded into:


<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:


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):


<div :style="{ display: ["-webkit-box", "-ms-flexbox", "flex"] }">


  • An extended component constructor can now also be used as a mixin. (@ktsn via #5448)
目录
相关文章
|
4天前
|
JavaScript 前端开发 开发者
Vue第1天:特性概览
Vue第1天:特性概览
|
4天前
|
前端开发 JavaScript Java
除了变量提升,JavaScript还有哪些特性?
【4月更文挑战第4天】JavaScript 特性包括函数作用域、动态类型、原型继承、异步编程、高阶函数、箭头函数、严格模式、对象字面量、模块系统和垃圾回收。这门语言支持多种编程模式,适合各种应用场景。想深入了解某特性,欢迎提问!😄
27 6
|
4天前
|
开发框架 JavaScript 算法
了解vue3的基本特性和底层原理
Vue3的底层原理涵盖了响应式系统的Proxy-based实现、组件的模板编译与渲染更新机制、组合式API带来的逻辑组织变革,以及其他关键特性的具体实现。这些原理共同构成了Vue3强大、高效、灵活的现代前端开发框架基础。
29 2
|
4天前
|
存储 JavaScript 前端开发
【JavaScript技术专栏】ECMAScript 6+新特性详解
【4月更文挑战第30天】ES6(ES2015)标志着JavaScript的重大更新,引入了类和模块、箭头函数、模板字符串、解构赋值、Promise、新数据类型Symbol、Set和Map集合等特性,提高了语言表达力和开发效率。后续版本继续添加新特性,如ES2016的`Array.prototype.includes`,ES2017的`async/await`,以及ES2018的`Object/rest`。学习和掌握这些特性对于提升开发质量和效率至关重要。
|
4天前
|
JavaScript 前端开发 编译器
Vue 3:新特性与改进技术详解
【4月更文挑战第25天】Vue 3 提升了编译和运行时性能,引入了Composition API实现灵活代码复用,新增Teleport用于任意位置渲染,支持Fragment多根节点及Suspense处理异步组件。同时,TypeScript支持增强,自定义指令和全局API也得到优化。Vue 3的新特性旨在提供更高效、灵活的开发体验,持续引领前端技术发展。
|
4天前
|
JavaScript 前端开发 Linux
JavaScript 的跨平台特性
【4月更文挑战第22天】JavaScript 的跨平台特性
25 8
|
4天前
|
JavaScript 前端开发 API
Vue3有哪些新特性
【4月更文挑战第15天】 Vue3带来了显著性能提升和开发体验优化:更快的渲染速度、更小的捆绑体积、改进的内存管理、增强的TypeScript支持、引入Composition API提升代码复用性,以及使用Proxy改进响应式数据处理。这些特性使Vue3成为更高效、灵活和可靠的框架,为开发者创造高性能应用提供了强大工具。
11 0
|
4天前
|
JavaScript 前端开发
JavaScript DOM 操作:如何检测浏览器是否支持某个特性?
【4月更文挑战第15天】使用Modernizr库检测浏览器特性:添加 `<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>` 到HTML,然后通过 `Modernizr.localstorage` 进行检测,如支持localStorage则执行相应代码,否则执行备用逻辑。
18 0
|
4天前
|
人工智能 前端开发 JavaScript
【前端设计】HTML+CSS+JavaScript基本特性
【前端设计】HTML+CSS+JavaScript基本特性
|
4天前
|
JavaScript 前端开发
Vue 中setup的特性
Vue 中setup的特性