1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Vue 基礎勉強 v-if

Last updated at Posted at 2023-11-14

(Vue.js 3.1.5を使用)

v-if
表示、非表示の切り替え。

javascript
const app = Vue.createApp({
    data: () => ({
        toggle: false
    })
})
app.mount('#app')
html
    <div id="app">
        <p v-if="toggle">こんにちは!</p>
    </div>

toggle: false
のままだと、表示されない。

1.PNG
toggle: true
に変更すると、表示される。

2.PNG

v-else

v-ifの表示条件以外(elseの条件)のとき表示する。

html
    <div id="app">
        <p v-if="toggle">こんにちは!</p>
        <p v-else="toggle">おはよう!</p>
    </div>

toggle: falseのとき、

9.PNG

toggle: trueのとき、

10.PNG

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?