Brayden
Brayden

Reputation: 17

Blank White Page in Vue.js with input null

I am having problems with vue.js. I want to show a piece of text if the input is null. Everything just shows up as a blank white page when I run my HTML page.

HTML:

    <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js Testing</title>
</head>

<body>
   <template>
    <div id="input">
        <span v-if="{{ input1 }} == null"> Empty </span>
        <p>{{ input1 }}</p>
        <input v-model="input1">
    </div>
   </template>

    <script src="vue.js"></script>
    <script src="scripts.js"></script>
</body>

</html>

And my JS:

var input = new Vue({
    el: '#input',
    data: {
      input1: 'Default'
    },
  })

Thanks for the help!

Upvotes: 1

Views: 257

Answers (2)

Michael Mano
Michael Mano

Reputation: 3440

This is because you are using curly bois inside of a v-if, No curly bois required.

    <div id="input">
        <span v-if="!input">Empty</span>
        {{ input }}
        <input v-model="input">
    </div>

https://codepen.io/michaelmano/pen/zYNmbjb

Upvotes: 2

Gautam Patadiya
Gautam Patadiya

Reputation: 1412

it should be like this:

<div id="input">
        <span v-if="!input1"> Empty </span>

        <p>{{ input1 }}</p>
        <input v-model="input1">
    </div>

Upvotes: 2

Related Questions