sveltejs-cn / svelte-cn

Svelte 中文文档
https://sveltejs-cn.github.io/svelte-cn/
16 stars 0 forks source link

Component bindings 翻译校准 #36

Closed yuwanli closed 5 years ago

yuwanli commented 5 years ago

组件绑定

bind:property={variable}
bind:this={component_instance}

你可以使用相同的机制给组件绑定属性。

<Keypad bind:value={pin}/>

组件还支持bind:this,允许你以动态数据的方式与组件实例进行交互。

注意,当按钮首次渲染的时候,我们不能使用{cart.empty},因为cart还是undefined,这样会抛出异常。

<ShoppingCart bind:this={cart}/>

<button on:click={() => cart.empty()}>
    Empty shopping cart
</button>