# 2020.11.13 今天是每日时报陪伴您的第 450 天
[文章] Vue 3.0 Ref-sugar 提案真的是自寻死路吗?:https://zhuanlan.zhihu.com/p/287842109?utm_source=wechat_session (opens new window)
[工具] 浏览器端 Awesome JavaScript 库,值得 Watch:https://github.com/sorrycc/awesome-javascript (opens new window)
# 配文 - Vue 3.0 Ref-sugar
setup suger
<script setup>
// imported components are also directly usable in template
import Foo from "./Foo.vue";
import { ref } from "vue";
// write Composition API code just like in a normal setup()
// but no need to manually return everything
const count = ref(0);
const inc = () => {
count.value++;
};
</script>
<template>
<Foo :count="count" @click="inc" />
</template>
ref-sugar 提案:
<script setup>
import Foo from "./Foo.vue";
// declaring a variable that compiles to a ref
ref: count = 1;
const inc = () => {
count++;
};
// access the raw ref object by prefixing with $
console.log($count.value);
</script>
<template>
<Foo :count="count" @click="inc" />
</template>
规范不是唯一权威来源,标准和规范往往滞后于实践同时也存在落后于时代的部分。而挑战权威是需要付出代价的,因为在开发者心里 框架 <= 语言
,只有极少数的团队,愿意去尝试从根本改变或者改善现状,Vue Ref-sugar 并不一定是正确的产物,但是需要被尊重。