Skip to content

destroy

销毁当前元素。

只读属性

destroyed: boolean

元素是否已被销毁。

关键方法

destroy ( )

移除 + 销毁当前元素,如存在子元素也会被遍历销毁。

归属

UI

示例

销毁移除

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = Rect.one({ fill: '#32cd79' }, 100, 100, 200, 200)

leafer.add(rect)

setTimeout(() => {

    rect.destroy() // 等同于 rect.remove() => rect.destroy()

}, 2000)

清空元素

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = Rect.one({ fill: '#32cd79' }, 100, 100, 200, 200)
const rect2 = Rect.one({ fill: 'blue' }, 300, 100, 200, 200)

leafer.addMany(rect, rect2)

setTimeout(() => {

    leafer.clear() // 清空并销毁所有子元素

}, 2000)

销毁应用

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = Rect.one({ fill: '#32cd79' }, 100, 100, 200, 200)

leafer.add(rect)

setTimeout(() => {

    leafer.destroy() // 应用销毁,默认为异步方式
    // leafer.destroy(true)  //  销毁应用,同步方式

}, 2000)

Released under the MIT License.