V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
gogobody
V2EX  ›  Vue.js

有没有人能帮忙看一个 Vue.js 的问题啊?[新手]

  •  
  •   gogobody · 2017-10-05 22:53:02 +08:00 · 2490 次点击
    这是一个创建于 2386 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题就是从一个页面跳转到另一个页面之后,使用 router.go(-1),浏览器地址变了,页面不跳转

    最外层 router 如下,导入了 landf:

    import lanf from '@/components/LandF/router/index'
    
    export default new Router({
        mode: 'history',
        base:base,
        routes: [
            {
                path: '/',
                name: 'PageTransition',
                component: PageTransition,
                meta: { KeepAlive: false },
    
                children: [
                    ...lanf
                ]
            }]
    })
    

    最外层的 PageTransition 组件

    <template>
        <div>
            <transition :name="transitionName">
                <keep-alive include="landf">
                    <router-view  class="child-view"></router-view>
                </keep-alive>
            </transition>
        </div>
    </template>
    
    <script>
        export default {
            data () {
                return {
                    transitionName: 'slide-left',
                }
            },
            beforeRouteUpdate (to, from, next) {
                if (isBack) {
                    this.transitionName = 'slide-right'
                } else {
                    this.transitionName = 'slide-left'
                }
                next()
            }
        }
    </script>
    

    然后是内层的 landf router:

    
    export default [
        {
            path: '/',
            name: 'landf',
            component:index,     
        },
        {
            path:'/detail/:id',
            name:'landfitemdetail',
            component:detail,
        }
    
    ]
    

    然后当我从 landf 点击事件跳转到 detail

    this.$router.push({
    	name:'landfitemdetail',
    	params:{
    		id:id,
    		state:state
    	}
    	})
    }
    

    一切正常。。。。。 但是,当我从 detail 点击返回..............

    goback(){
    	this.$router.back(-1)
    }
    

    可以看见浏览器的地址已经改变了,然而页面并没有任何变动。。。再点击一次,就回到我的 chrome 首页了。。。。 求救啊~!!!!!!!

    6 条回复    2017-10-06 18:49:56 +08:00
    notes
        1
    notes  
       2017-10-05 23:01:49 +08:00 via Android
    额,看不出问题,也许 this.$route 用法出错
    gogobody
        2
    gogobody  
    OP
       2017-10-05 23:13:42 +08:00 via Android
    @notes TT .... 好蛋疼啊
    CupTools
        3
    CupTools  
       2017-10-06 02:42:38 +08:00 via iPhone
    PageTransititon 里面的 isBack 是哪来的时候🤷‍♀️
    xiaojie668329
        4
    xiaojie668329  
       2017-10-06 09:01:41 +08:00 via iPhone
    this.$router.back()就是后退,等于 this.$router.go(-1),没有 back(-1)这种写法吧。
    gogobody
        5
    gogobody  
    OP
       2017-10-06 18:49:42 +08:00 via Android
    @CupTools 额,这个是我自己定义的。那个我找到原因了,我在 befrerouteleave 里面把当前组件 destroy 了,然后导致了无法 go(-1)到前一个页面,请问是啥原因呢
    gogobody
        6
    gogobody  
    OP
       2017-10-06 18:49:56 +08:00 via Android
    @xiaojie668329 我在 befrerouteleave 里面把当前组件 destroy 了,然后导致了无法 go(-1)到前一个页面,请问是啥原因呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4595 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 01:05 · PVG 09:05 · LAX 18:05 · JFK 21:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.