2.6.10
https://codesandbox.io/s/vue-template-7hwty
$attrs
๋ฉ๋๋ค.Render ํจ์๋ ํ ๋ฒ ํธ์ถ๋๋ฉฐ $attrs
์ปดํฌ๋ํธ๋ ๋ณ๊ฒฝ๋์ง ์์ต๋๋ค.
Render๊ฐ ๋ ๋ฒ ํธ์ถ๋๊ณ ํ์ ์ปดํฌ๋ํธ์ props
์ ๋์ผํ ํค๋ฅผ ๊ฐ์ง attrs
๊ฐ ์ ๊ฑฐ๋ฉ๋๋ค.
https://vuejs.org/v2/guide/components-dynamic-async.html#Handling -Loading์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ์ง์ฐ๋ก๋ ๋ ๊ตฌ์ฑ ์์์๋ก๋ ๋ฐ ๋คํธ์ํน ์ค๋ฅ๋ฅผ ์ฒ๋ฆฌํด์ผํ๋ ํ๋ก์ ํธ ์ฌ์ฉ์ ์ง์ ๋ก๋ ๊ตฌ์ฑ ์์๋ฅผ ๋ง๋ค์์ต๋๋ค. -๋ด ๊ฒฝ์ฐ์๋ ์ํ. ์ด ๋ฒ๊ทธ๋ ๋ค์ด๋ก๋ ๋ ๊ตฌ์ฑ ์์๋ฅผ ๋ฐ์์ฑ์ ์ถ๊ฐํ์ง ์์์ผ๋ก์จ ์๋ต ํ ์ ์์ต๋๋ค (์ธ๋ถ ๋ฐ์ดํฐ๋ฅผ ๋ณ์๋ก).
$attrs
: {...this.$attrs}
์ ๋ณต์ฌ๋ณธ์ ์ฌ์ฉํ๋ฉด ๋ฌธ์ ๊ฐ ์ ๊ฑฐ๋ฉ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด ์ํ์ ์ฌ์ฉํด์ผํฉ๋๋ค.
render(h) {
console.log("Attributes of loader:", this.$attrs);
if (this.targetComponent) {
return h(this.targetComponent, {
props: this.$attrs // Change attrs to props๏ผnot `attrs: this.$attrs`
});
} else {
return h("div", "Component is loading");
}
}
์ํ์ ๊ฐ์ ธ ์ค๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ์
const targetComponent = {
props: {
// COMMENT PROP
someProp: {
type: String
}
},
render(h) {
console.log("Props of target", this.$props); // You can not get $props when render params only has attrs
return h("div", "WITH PROP:" + this.someProp);
}
};
์์ฑ์ ๋ณต์ฌํ๊ณ props๋ก ์ ๋ฌํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋์ง๋ง ๋์ผํ ํค๋ฅผ ๊ฐ์ง props๋ฅผ ํฌํจํ๋ ์์์ ๋ ๋๋งํ๊ธฐ ๋๋ฌธ์ ๋ถ๋ชจ ๊ตฌ์ฑ ์์ $attrs
์ด ์ ๋ณ๊ฒฝ๋๋์ง ๊ถ๊ธํฉ๋๋ค.
$attrs
๊ฐ์ฒด๊ฐ ์ฌ ํ ๋น ๋์๊ธฐ ๋๋ฌธ์
๋๋ค. ๋๋ ์ด๋ฏธ ๋ค๋ฅธ ๊ณณ์์์ด ๋ฌธ์ ๋ฅผ ๋ณด์๋ค๋ ๊ฒ์ ์๊ณ ์์๋ค.
https://github.com/vuejs/vue/issues/10115์ ์ค๋ณต