這與我之前的帖子有些相關,在那里我學到了更多關于動作的知識。
我一直在試圖弄清楚如何使用這個漂亮的功能,但在過去的幾個小時里我似乎有點卡住了。
在我的組件中,我創建了一個 SVG 視圖框,如下所示:
<svg id="pitch" viewBox={`0 0 ${width} ${height}`} use:foo>
</svg>
那么drawPitch就是這個函式:
function foo(node) {
// the node has been mounted in the DOM
let g = node.append('h1');
g.text("This is the text I'd like to render to check that it works");
return {
destroy() {
// the node has been removed from the DOM
}
};
}
根據我在檔案中的理解,use:foo將呼叫節點傳遞給 foo,所以我認為直接將 svg 元素附加到它應該可以作業。我需要以某種方式更新它嗎?
這是一個帶有可重現代碼的 repl。
我收到以下錯誤:
“svelte”包中缺少“./types/runtime/internal/keyed_each.js”匯出
謝謝!
uj5u.com熱心網友回復:
我希望代碼foo以 . 開頭d3.select(node),并且一切都以此為基礎。否則 d3 生成的 DOM 樹根本不會連接到你的檔案。或者,結果元素 ( selection.node()) 必須附加到node某個點。
該錯誤聽起來非常不相關,可能需要更多背景關系。
注意:您不能將 HTML 直接添加到 SVG,SVG 用于類似畫布的矢量圖形,而不是檔案布局。如果要插入文本,請使用<text>元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/504324.html
