广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >vue实力踩坑 当前页push当前页无效的解决
  • 704
分享到

vue实力踩坑 当前页push当前页无效的解决

2024-04-02 19:04:59 704人浏览 泡泡鱼
摘要

目录Vue当前页push当前页无效vue push报错TypeError: Cannot read property ‘push‘ of undefined解

vue当前页push当前页无效

当在当前页面中push页面跳转当前页,只是push的参数不同时,只能用字符串拼接,parames和query都不会起作用。不知道为什么。。。

比如说:当前页的url是

/invest/myinvest?page=1&day=0-30`

但是想点击的时候改变参数,所以就

this.$router.push({path:'/invest/myinvest?',query:{page:1,day:'0-30'}})

然而并无卵用。。。。

只能:

this.$router.push("/invest/myinvest?page="+currentPage+"&day="day);

vue push报错

TypeError: Cannot read property ‘push‘ of undefined

axiOS.post('/processing/', {})
     .then(function (response) {
       console.log(response.data);
       if (response.data == 'no_processing') {
         alert("文章分析失败!");
         return;
       }else if(response.data=='empty_processing'){
         alert("文章数据为空,无法分析!")
         return;
       }
       response.data.forEach(function(element){
          this.processing_tableData.push(element);  //“push”报错
          console.log(element);
        });
       console.log("ok_processing")
     })
     .catch(function (error) {
       console.log(error);
     })

报错:

TypeError: Cannot read property ‘push’ of undefined

解决方法

在外部定义一个值指代Vue实例

var self = this; //外部定义
axios.post('/processing/', {})
     .then(function (response) {
       console.log(response.data);
       if (response.data == 'no_processing') {
         alert("文章分析失败!");
         return;
       }else if(response.data=='empty_processing'){
         alert("文章数据为空,无法分析!")
         return;
       }
       response.data.forEach(function(element){
          self.processing_tableData.push(element);  //把“this”=》“self”
          console.log(element);
        });
       console.log("ok_processing")
     })
     .catch(function (error) {
       console.log(error);
     })

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。 

--结束END--

本文标题: vue实力踩坑 当前页push当前页无效的解决

本文链接: https://www.lsjlt.com/news/145456.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • vue实力踩坑 当前页push当前页无效的解决
    目录vue当前页push当前页无效vue push报错TypeError: Cannot read property ‘push‘ of undefined解...
    99+
    2022-11-13
  • vue中当前页push当前页无效怎么解决
    这篇文章主要介绍“vue中当前页push当前页无效怎么解决”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“vue中当前页push当前页无效怎么解决”文章能帮助大家解决问题。vue当前页push当前页无...
    99+
    2023-06-29
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作