Vue 3.3 已正式發布,代號”Rurouni Kenshin”(浪客劍心)。
公告寫道,此版本專注於改進開發者使用體驗—— 特別是SFC<script setup>
與TypeScript 的結合使用。一同發布的還有 Vue Language Tools 1.6(舊Volar),解決了Vue 與TypeScript 一起使用時許多長期存在的痛點。
升級到3.3 時,建議同時更新以下依賴項:
- volar / vue-tsc@^1.6.4
- vite@^4.3.5
- @vitejs/plugin-vue@^4.2.0
- vue-loader@^17.1.0 (if using webpack or vue-cli)
改進開發者使用<script setup>
+ TypeScript 的體驗
- 面向宏支援類型導入和復雜類型
<script setup lang="ts">
import type { Props } from './foo'
// imported + intersection type
defineProps<Props & { extraProp?: string }>()
</script>
<script setup lang="ts" generic="T">
defineProps<{
items: T[]
selected: T
}>()
</script>
<script setup lang="ts" generic="T extends string | number, U extends Item">
import type { Item } from './types'
defineProps<{
id: T
list: U[]
}>()
</script>
// BEFORE
const emit = defineEmits<{
(e: 'foo', id: number): void
(e: 'bar', name: string, ...rest: any[]): void
}>()
// AFTER
const emit = defineEmits<{
foo: [id: number]
bar: [name: string, ...rest: any[]]
}>()
- 使用
defineSlots
設置slots 類型
<script setup lang="ts">
defineSlots<{
default?: (props: { msg: string }) => any
item?: (props: { id: number }) => any
}>()
</script>
實驗性功能
<script setup>
import { watchEffect } from 'vue'
const { msg = 'hello' } = defineProps(['msg'])
watchEffect(() => {
// accessing `msg` in watchers and computed getters
// tracks it as a dependency, just like accessing `props.msg`
console.log(`msg is: ${msg}`)
})
</script>
<template>{{ msg }}</template>
<!-- BEFORE -->
<script setup>
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
console.log(props.modelValue)
function onInput(e) {
emit('update:modelValue', e.target.value)
}
</script>
<template>
<input :value="modelValue" @input="onInput" />
</template>
<!-- AFTER -->
<script setup>
const modelValue = defineModel()
console.log(modelValue.value)
</script>
<template>
<input v-model="modelValue" />
</template>
詳情查看完整Changelog。
#Vue #33浪客劍心發布 #科技資訊 #中文開源技術交流社區
You may also like
相关贴文:
近期文章
標籤雲
Dropshipping
ecommerce
JavaScript
Joomla
OSCHINA博客
python
REBELLION
Shopify
Shopify 商店設置
Shopify 直銷
Woocommerce
WordPress
代發貨
刀塔2
和
商店
商業
喬姆拉
在
如何創建 Shopify 商店
如何在
如何建立 Shopify 商店
如何開始代出貨
年
店舖教學
店鋪化
店鋪培訓
教學
獲獎產品
直銷 Shopify
直銷教程
科技資訊
程式碼
網路業務
網路賺錢
臉書廣告
與
行銷
詳解
購物
跨平台
運輸船
適合初學者的 Shopify 教學課程
適合初學者的直銷
電子商務