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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>输入框切换显示与隐藏效果</title>
</head>
<body>
  <div id="app">
    <button @click="show = !show">{{show?"显示":"隐藏"}}</button>
    <!-- 不加key达不到input框切换的效果 -->
    <input type="text" v-if="show==true" :key="2">
    <input type="text" v-else :key="3">
  </div>
</body>
<script src="./vue.js"></script>

<script>
  const vm = new Vue({
    el: "#app",
    data: {
      show:true,
    }
  })

</script>

</html>
Logo

前往低代码交流专区

更多推荐