首页 > 其他分享 >vue-组件

vue-组件

时间:2023-07-10 11:47:12浏览次数:29  
标签:vue demo button component Vue template 组件

<!DOCTYPE html>
<html>
<head>
    <title>Vue Demo</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <div id="firstVue">
     <p>{{msg}}</p>
    <button-demo></button-demo>  
    <child v-bind:message="msg"></child>
    <button-counter></button-counter>    
    </div>
    
     
</body>
<script type="text/javascript">

   Vue.component('button-demo',{
        template:'<button>Hello button-demo!</button>'
    });
    //注册了'button-demo'以后,<button-demo></button-demo>就等价于<button>Hello here!</button>
    
    // 组件 child
     Vue.component('child', {
      // 声明 props
      props: ['message'],
      template: '<div><span>{{ message }}</span></div>'
    });

    //定义button-counter组件
    Vue.component('button-counter',{
        //定义数据
        data:function(){
            return {
                count: 0
            }
        },
        //定义方法
        methods:{
            clickAdd: function(){
                this.count++
            }
        },
        template :'<button @click="clickAdd">You clicked me {{count}} times</button>'

    });

    var myVue = new Vue({
        el: "#firstVue",
        data:{
         msg:"hello world"
        }
        
    })
</script>

</html>

  

标签:vue,demo,button,component,Vue,template,组件
From: https://www.cnblogs.com/boye169/p/17540562.html

相关文章

  • Vue监听store中数据变化的2种方式
    http://chart.zhenglinglu.cn/pages/068e2f/#方式一......
  • Vue路由新开页面跳转和传参传递
    需求:在后台管理系统首页列表项中,点击详情跳转到系统中指定菜单的路由要求新开窗口并需要带上参数查询。第一种方法:1const{id}=item;2letrouteUrl=this.$router.resolve({3path:'/xxx',//路由地址4query:{id}//参数信息5});6window.open(ro......
  • VUE中定义全局配置方法
    方法一:main.ts中constwsapi="ws://localhost:8081";constappConfig={wsapi,};constapp=createApp(App);//ProvidetheappConfigasaglobalpropertyapp.config.globalProperties.$appConfig=appConfig;app.use(store)VUE中1、setup方法中co......
  • vue实例
    <!DOCTYPEhtml><html><head><metacharset="utf-8"><title>Vue测试实例</title><scriptsrc="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script></head><body><divid=......
  • vue--day13--watch与computed的区别
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>watch实现名字案例</title><scri......
  • vue--day12--深度监视
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>天气案例--监听属性</title><scrip......
  • vue-day12--监听属性
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>天气案例--监听属性</title><scrip......
  • vue--day11--计算属性实现名字案例简写
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>计算属性实现名字案例简写</title><scr......
  • vuex
    1.概念在Vue中实现集中式状态(数据)管理的一个Vue插件,对vue应用中多个组件的共享状态进行集中式的管理(读/写),也是一种组件间通信的方式,且适用于任意组件间通信。2.何时使用?多个组件需要共享数据时3.搭建vuex环境1、创建文件:src/store/index.js//引入Vue核心库importVuefr......
  • vue--day11--计算属性实现名字案例
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>计算属性实现名字案例</title><scrip......