怎么才能到一行。v-if用法

628 篇文章 6 订阅
本文演示了Vue.js中使用模板语法显示条件内容、数据绑定以及创建组件的过程。从简单的`v-if`指令到数据初始化,再到输入字段和按钮的添加,逐步展示了Vue应用的基本构建块。最后,通过引入`yes`和`no`属性来控制标题的显示,以及添加`name`属性完成更复杂的模板结构。
摘要由CSDN通过智能技术生成
<!DOCTYPE html>

<body>
<div id="app">
  <h1>Yes!</h1>
  <span><h1>Age: </h1><h1 v-if="age>20">{{ age }}</h1></span>
  <h1>Yes!</h1>
</div>

<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
        age: 28
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

为啥不对

<!DOCTYPE html>

<body>
<div id="app">
  <h1>Yes!</h1>
  <h1>Age: </h1><h1 v-if="age>20">{{ age }}</h1>
  <h1>{{ name }}</h1>
  
</div>



<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
        age: 28
        name: Will Smith
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

又加了

<!DOCTYPE html>

<body>
<div id="app">
  <h1>Yes!</h1>
  <h1>Age: </h1>
  <h1 v-if="age>20">{{ age }}</h1>
  <h1>{{ name }}</h1>
  <p>username: <input type="text"></p>
  <p>password: <input type="text"></p>
  <button>登录</button>
</div>



<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
        age: 28, 
        name: Will Smith
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

yes又不见了

<!DOCTYPE html>

<body>
<div id="app">
  <h1 v-if="yes">Yes!</h1>
  <h1 v-if="no">No!</h1>
  <h1 v-if="age > 20">Age: {{ age }}</h1>
  <h1>{{ name }}</h1>
  <p>username: <input type="text"></p>
  <p>password: <input type="text"></p>
  <button>登录</button>
</div>



<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
        age: 28, 
        
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

改正了,但是为什么return这里直接加name不行

<!DOCTYPE html>

<body>
<div id="app">
  <h1 v-if="yes">Yes!</h1>
  <h1 v-if="no">No!</h1>
  <h1 v-if="age > 20">Age: {{ age }}</h1>
  <h1>{{ name }}</h1>
  <p>username: <input type="text"></p>
  <p>password: <input type="text"></p>
  <button>登录</button>
</div>



<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
       yes: true,
       no: false,
        age: 28, 
        
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

这个name是怎么改的

<!DOCTYPE html>

<body>
<div id="app">
  <h1 v-if="yes">Yes!</h1>
  <h1 v-if="no">No!</h1>
  <h1 v-if="age > 20">Age: {{ age }}</h1>
  <h1>Name: {{ name }}</h1>
  <p>username: <input type="text" usename="name"></p>
  <p>password: <input type="text"></p>
  <button>登录</button>
</div>



<script src="https://unpkg.com/vue@next"></script>
<script>
 const vm = Vue.createApp({
   data() {
     return {
       yes: true,
       no: false,
       age: 28, 
       name: Will Smith,
     }
   }
 }).mount('#app')

  </script>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值