Vue的基本组件2(show,bind)

简介: Vue的基本组件2(show,bind)

简介:本文旨在用最短的篇幅和例子,代入大家入门vue,也是本博主的一个学习记录,本文主要介绍的组件有,v-show,v-bind。

v-show

简介:v-show用来控制标签是显示还是隐藏

学习代码:

<!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>v-show</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h2 v-show="true">Vue欢迎您!</h2>
        <!-- 对于show中显示的变量isVisible如果为true那么就显示文本中的内容,如果为false就不现实 -->
        <h2 v-show="isVisible">这是被控制显示的文本!</h2>
        <input type="button" value="显示隐藏按钮" @click="showmessage">
    </div>
</body>
    <script>
        const app = new Vue({
            el:"#app",
                data:{
                    isVisible:false
                },
                methods:{
                    showmessage(){
                    this.isVisible = !this.isVisible
                }
            }
        });
    </script>
</html>

v-bind

v-bind: 用来绑定标签的属性从而通过vue动态修改标签的属性。

学习代码:

<!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入门</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <img v-bind:src="imagename" v-bind:alt="title" v-bind:width="width" v-bind:height="height">
    </div>
</body>
    <script>
        const app = new Vue({
        el:"#app",
        data:{
            title:"这是一张5g图片",
            imagename:"../01_初始Vue/images/5g.png",
            width:150,
            height:150
        },
        methods:{
        }
        });
    </script>
</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入门</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <img :src="imagename" v-bind:alt="title" v-bind:width="width" v-bind:height="height">
    </div>
</body>
    <script>
        const app = new Vue({
        el:"#app",
        data:{
            title:"这是一张5g图片",
            imagename:"../01_初始Vue/images/5g.png",
            width:150,
            height:150
        },
        methods:{
        }
        });
    </script>
</html>

运行结果:

相关文章
|
JavaScript
Vue中如何实现兄弟组件之间的通信
在Vue中,兄弟组件可通过父组件中转、事件总线、Vuex/Pinia或provide/inject实现通信。小型项目推荐父组件中转或事件总线,大型项目建议使用Pinia等状态管理工具,确保数据流清晰可控,避免内存泄漏。
1058 2
|
缓存 JavaScript
vue中的keep-alive问题(2)
vue中的keep-alive问题(2)
929 137
|
人工智能 JavaScript 算法
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
2230 0
|
JavaScript UED
用组件懒加载优化Vue应用性能
用组件懒加载优化Vue应用性能
|
人工智能 JSON JavaScript
VTJ.PRO 首发 MasterGo 设计智能识别引擎,秒级生成 Vue 代码
VTJ.PRO发布「AI MasterGo设计稿识别引擎」,成为全球首个支持解析MasterGo原生JSON文件并自动生成Vue组件的AI工具。通过双引擎架构,实现设计到代码全流程自动化,效率提升300%,助力企业降本增效,引领“设计即生产”新时代。
1123 1
|
JavaScript 安全
在 Vue 中,如何在回调函数中正确使用 this?
在 Vue 中,如何在回调函数中正确使用 this?
848 0
|
JavaScript
Vue的非父子组件之间传值
全局事件总线 一种组件间通信的方式,适用于任意组件间通信
390 0
|
缓存 JavaScript 前端开发
Vue Props、Slot、v-once、非父子组件间的传值....
Vue Props、Slot、v-once、非父子组件间的传值....
347 0
|
JavaScript
Vue中父子组件传值
先在⽗组件中给⼦组件的⾃定义属性绑定⼀个⽗组件的变量
354 0
|
JavaScript
vue 组件传值
vue 组件传值
341 0