我正在尝试在值更改时触发组件更新
它适用于 css 更新,例如 '$: cssColorValue = calcRandomColor()' 但如果我使用数组,例如 '$: values = [...newValues]'
<script>
import Chip from "./Chip.svelte";
import st from "../style-config.js";
export let width = st.chip_bar.width;
export let height = st.chip_bar.height;
let border = st.chip_bar.border;
export let center = false;
export let color = "";
export let cl = "";
export let close = true;
export let values = [];
export let disabled = "";
let value = "";
function add_value(event) {
if (event.code === "Enter") {
values.push(value);
console.log(values);
value=''
}
}
function remove_value(e) {
console.log(e);
var index = values.indexOf(e.value);
if (index > -1) {
arr.splice(index, 1);
}
}
$: input_style = ` text-black w-auto h-auto font-medium ml-1 outline-none ${cl}`;
$: chip_bar_style = ` ${
st.round
} text-black w-${width} h-${height} text-middle ${
border ? "border" : ""
} outline-none ${st.shadow} ${
st.chip_bar.border
} pl-1 pr-1 pt-1 pb-1 inline-block ${cl}`;
</script>
<div class="{chip_bar_style} on:hover={st.chip_bar.focus}">
{#each values as text}
<Chip {text} on:click={remove_value} />
{/each}
<input
type="text"
class={input_style}
bind:value
on:keydown={add_value}
{disabled} />
</div>
我想要的是让 Svelte 重新渲染 for each 循环