在 Vue.js 中,可以使用 <router-link> 标签或者 this.$router.push() 方法实现点击按钮跳转到另一个界面。

使用 <router-link> 标签:

  1. 在 <template> 标签中添加 <router-link> 标签,设置 to 属性为目标路由的路径。
  2. 将按钮放置在 <router-link> 标签中。

示例代码:

<template>
  <div>
    <router-link to='/target-page'>
      <button>跳转到目标界面</button>
    </router-link>
  </div>
</template>

使用 this.$router.push() 方法:

  1. 在点击按钮的事件处理函数中,使用 this.$router.push() 方法跳转到目标路由。
  2. 目标路由可以是路径字符串,也可以是一个包含 path 属性的对象。

示例代码:

<template>
  <div>
    <button @click='gotoTargetPage'>跳转到目标界面</button>
  </div>
</template>

<script>
export default {
  methods: {
    gotoTargetPage() {
      this.$router.push('/target-page');
    }
  }
}
</script>

以上两种方法都可以实现点击按钮跳转到另一个界面,具体选择哪种方式取决于具体的需求和使用场景。

Vue.js 点击按钮跳转界面:两种方法解析