Vue的一些操作

标签属性赋予变量的值
  • 属性值前加一个:**赋的值就为变量的值,实例如下 **inputname属性值为sss

<template>
    <input :name="name">
</template>

<script>
    export default{
        data(){
            return{
                name;'sss'
            }
        }
    }
</script>
延时
clearTimeout(this.timer);  *//清除延迟执行* 

this.timer = setTimeout(()=>{
                            this.loading=false
                            },500);

页面刷新
页面刷新
location.reload();
页面跳转传参
//query,用路径跳转

this.$router.push({
    path:'/about',
    query:{
        name:'about',
        code:111
    }
})

#接收参数
this.$route.query

是{name: "about", code: "111"}
页面跳转——window.location.href
window.location.href = 'http://www.baidu.com';
实现后退功能
function backWay() { 
    // history.back();
        history.go(-1); 
        }
局部刷新

在Vue中,我们经常遇到对数据进行增删改查的操作之后, 希望页面显示的是我们操作之后最新的数据, 为了避免重新做axios请求, 此时用到组件的刷新是很方便的了, 以下便是我做项目中总结的组件局部刷新的方法:

  • **首先需要修改App.vue **
<template>
  <div id="app">
    <router-view v-if="isRouterAlive"/>
  </div>
</template>
<script>
export default {
  provide(){
    return{
      reload:this.reload
    }
  },
  data(){
    return{
      isRouterAlive:true
    }
  },
  methods:{
    reload(){
      this.isRouterAlive=false;
      this.$nextTick(function(){
        this.isRouterAlive=true
      })
    }
  }
}
</script>
  • 到需要刷新的页面进行引用,使用inject导入引用reload,然后直接调用即可

img

vue离开当前页面时调用的函数(不在methods里)

destroyed: function () {
   console.log("我已经离开了!");
 
this.doSomething();
 },
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值