nuxt.js ๋ ธํธ
- ๋ฅ์ง
- Development
- ๋ถ๋ฅ
- Javascript
- ๋ฑ๋ก์ผ
no-ssr component
ํด๋ผ์ด์ธํธ์์๋ง ๋ ๋๋งํ ์ ์๋ ์ปดํฌ๋ํธ
https://nuxtjs.org/api/components-no-ssr/
<template>
<div>
<sidebar />
<no-ssr placeholder="Loading...">
<!-- this component will only be rendered on client-side -->
<comments />
</no-ssr>
</div>
</template>
๋์ค์๋ <no-ssr/>์ด ์๋ <client-only/>๋ก ์ฌ์ฉ๋๊ณ ์์.
<client-only>
<component/>
</client-only>
Array ํ์ ๋ฐ์ดํฐ์ ์์๊ฐ์ ์ ๋ฐ์ดํธ ํ๋๋ฐฉ๋ฒ
this.items[2] = true;์ ๊ฐ์ ๋ฐฉ์์ผ๋ก data ๊ฐ์ ๋ณ๊ฒฝํ๋๊ฑด ๋ถ๊ฐ๋ฅํ๋ค. ํ์ง๋ง this.$set()๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ์
๋ฐ์ดํธ๋ฅผ ํ ์ ์๋ค.
this.$set(this.items, idx, 'apple');
<nuxt-link/>์ปดํฌ๋ํธ์์ ์ด๋ฒคํธ ์ปจํธ๋กค
<nuxt-link/> ์ปดํฌ๋ํธ๋ก to ์์ฑ๊ฐ์ผ๋ก ํ์ด์ง ์ด๋์ ํ๋๋ฐ ์ด์ฉ๋๋ ํ์ด์ง ์ด๋ํ์ง ์๊ณ ํด๋ฆญ ์ด๋ฒคํธ๋ก๋ง ์ฌ์ฉํ๊ณ ์ถ์๋๊ฐ ๋ง๋ค.
ํ์ง๋ง ์ด์ํ๊ฒ๋ ๋ ํผ๋ฐ์ค๊ฐ ์ ์ด์ ๋ฌด๋ฆฌํด์ <button/>์๋ฆฌ๋จผํธ๋ก ์ฌ์ฉํ๊ณ ์์๋ค. (ํ์ง๋ง ๋ง๋ ๋ฐฉ์์ด๊ธด ํจ..)
๋ค์๊ณผ ๊ฐ์ด ํด๋ฆญ ์ด๋ฒคํธ๋ง์ผ๋ก ์ฌ์ฉํ๊ณ /foo ์ฃผ์๋ก ์ด๋ํ์ง ์๊ฒ๋๋ค.
<nuxt-link to="/foo" event="" @click.native="$emit('click', $event)"/>
์์ฑ๊ฐ event์ ๊ธฐ๋ณธ๊ฐ์ click์ด๊ณ , https://router.vuejs.org/kr/api/#event ๋ฌธ์๋ฅผ ํตํ์ฌ ์์ธํ ๋ด์ฉ์ ํ์ธํ ์ ์๋ค.
<nuxt-link/>์ปดํฌ๋ํธ์์ replace ์ด์ฉํ๊ธฐ
๊ธฐ๋ณธ์ ์ผ๋ก <nuxt-link/> ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฉํ๋ฉด push๋ฐฉ์์ผ๋ก ์ฌ์ฉ๋๋๋ฐ(ํ์คํ ๋ฆฌ ์ถ๊ฐ) replace๋ฐฉ์์ผ๋ก ๋ง์ง๋ง ํ์คํ ๋ฆฌ์์ url ๊ต์ฒดํ๋๋ก ํ๋ค.
<nuxt-link to="/foo" replace/>
0๊ฐ์ ๋๊ธ
๋ฑ๋ก๋ ๋๊ธ์ด ์์ต๋๋ค.