vue页面跳转与传值

跳转

#<script>
this.$router.push({path:'/index'})
#template
<button @click="goToHome">首页</button>
#实用router-link
<router-link to="/staff-list">
  <div class="items ">人员列表</div>
</router-link>

传值

方法一:通过路由带参数进行传值

#两个组件 A和B,A组件通过query把orderId传递给B组件(触发事件可以是点击事件、钩子函数等)
this.$router.push({ path: '/conponentsB', query: { orderId: 123 } }) // 跳转到B
#在B组件中获取A组件传递过来的参数
this.$route.query.orderId
#注意实用query可以正常传值,如果实用params需要加name属性(同path同级)

猜你喜欢

转载自blog.csdn.net/benben0729/article/details/83990414