AllenCai 最近的时间轴更新
AllenCai

AllenCai

V2EX 第 435633 号会员,加入于 2019-08-13 13:44:47 +08:00
AllenCai 最近回复了
33 天前
回复了 nerkeler 创建的主题 Vue.js 有无 vue3 的入门案例
@CHTuring chatgpt-web 的大佬,你好
70 天前
回复了 gtalk 创建的主题 职场话题 来晒晒你的中秋节福利
一箱水果
230 天前
回复了 gniviliving 创建的主题 问与答 待业中的老婆怀孕了
帮我改成一首七言诗:

备孕三年久,裸辞返乡创。
半年失败苦,屁股债摞摞。
深圳再就业,妻子转行教。
考取教资证,欲考小学师。
面试没通过,深圳教育衰。
报名参加测,三月学习到。
催生检查孕,当月即怀孕。
目前待业中,企业对孕慎。
隐瞒难入职,诚信有问题。
坦诚更无望,产假粤八十。
想法找社保,孕检能报销。
自己缴部分,减轻经济担。
深圳能自主,缴纳医社保。
孕期检查诊,能否报销些?
创业失败困,经济压力大。
230 天前
回复了 JinTianYi456 创建的主题 问与答 求个算法,均摊问题
function shareDiscount(discount, prices) {
// 计算总价和每个数在总价中所占比例
const total = prices.reduce((acc, cur) => acc + cur);
const ratios = prices.map(price => price / total);

// 分别计算每个数获得的优惠金额并更新它
let remain = discount;
const discounts = ratios.map(ratio => {
const curDiscount = ratio * discount;
remain -= curDiscount;
return curDiscount;
});

// 如果分配完后剩余的优惠金额仍然大于 0 ,则将剩余的优惠金额加到当前值最小的数字上
while (remain > 0) {
// 找到当前最小值和其对应的索引
const minPrice = Math.min(...prices);
const minIndex = prices.indexOf(minPrice);

// 将优惠金额加到最小值上,并保证不会小于 0
const curDiscount = Math.min(remain, discounts[minIndex] + minPrice);
prices[minIndex] -= curDiscount;
discounts[minIndex] += curDiscount;
remain -= curDiscount;
}

// 将每个数字和它对应的优惠金额相加计算最终价格
const finalPrices = prices.map((price, index) => Number((price - discounts[index]).toFixed(2)));
return finalPrices;
}
@shakukansp 是的,因为 reactive 的 proxy 化时深层的,所以第一层解开会有第二层的 proxy 在,只有当值为基础类型时,解构赋值会把引用断开
shakukansp 他说的是解构会导致 proxy 对象被解开,触发不了 proxy 里的 getter ,是原因所在。
johnkiller 他说的是将之前的 proxy 引用放在一个新作用域里,所以解构后还是在使用之前的 proxy 引用,实现 OP 的效果,是一种解决办法。
我先打脸我自己,其实#70 这样写根本就不用 toRefs
看了这么久,其实就是 proxy 的问题
我觉得两个人说的都对,只是各自角度不同。
还有 demo2 改成 toRefs 会不会就实现 OP 的效果了?只谈实现不谈原理。
<script>
import { defineComponent, ref, toRefs, computed, reactive } from "vue";

function useCounter() {
const number = ref(0);
const count = computed(() => number.value + 1);
return toRefs({
// count 是一个 ref
count,
number,
});
}
export default defineComponent({
setup() {
const counter = useCounter();

return () => {
// 解构 count 为 ref
return <Display {...counter} />;
};
},
});

function Display(props) {
return (
<div>
<button onClick={() => props.number.value++}>inc</button>
<div>{props.count.value}</div>
</div>
);
}
</script>
You’re #869034 in line
2022-10-20 16:47:17 +08:00
回复了 yc23232 创建的主题 程序员 面试紧张怎么缓解
当这份工作对你来说并不是特别重要的时候,就不会紧张.
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4981 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 49ms · UTC 01:23 · PVG 09:23 · LAX 17:23 · JFK 20:23
Developed with CodeLauncher
♥ Do have faith in what you're doing.