• vuejs keep-alive


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>vue</title>
    
         <!-- 
        <script src="vue.js"></script>
        -->
        
     <script src="https://unpkg.com/vue/dist/vue.js"></script>
     
    </head>
    <body> 
     
     <div id="counter-event-example">
     <keep-alive>   <!-- 把切换出去的组件保存到内存中 -->
      <component v-bind:is="currentView">
      <!-- 组件在 vm.currentview 变化时改变! -->
      </component>  
      </keep-alive>
    </div>
     
    <script> 
    
     
    // 外部注册组件
    Vue.component('outside', {
      
      template: '<p>Welcome from outside!</p>',
      data: function () {
        return {
          someChildProperty: true
        }
      }
    })
    
    
    // 内部自带组件
    var vm = new Vue({
      el: '#counter-event-example',
      data: {
        currentView: 'home'
      },
      components: {
        home:{
            template:'<div><span>home....</span><span> header </span></div>'                
            ,
                    data: function () {
                    return {
                    someChildProperty: true
                    }
                    }
        },
        posts:{
            template:'<span>posts....</span>',
                    data: function () {
                    return {
                    someChildProperty: true
                    }
                    }
        },
        archive:{
            template:'<span>archive....</span>',
                    data: function () {
                    return {
                    someChildProperty: true
                    }
                    }
        }
      }
    })
    
    
    // 可以在 console 修改   vm.currentView='posts'  刷新视图
    
    </script>
    
    
    
    </body>
    </html>
  • 相关阅读:
    jstree 实现异步加载子节点
    创建 widget 窗口小组件
    Android(permission)常用权限
    Android 之 补间动画
    补间动画之 AlphaAnimation
    (转)向对象开发与面向组件开发的区别
    Android Drawable文件夹对应像素密度
    Notification(通知) 简单用法
    AlarmManager 用法
    关于IntentService 用法
  • 原文地址:https://www.cnblogs.com/rojas/p/6595461.html
Copyright © 2020-2023  润新知