2025-07-29

Ionic 專案,無法切換頁面

我的 Ionic 專案有以下兩個 .vue 檔案(這邊僅列<template> tag 的 code)

<template>
	<ion-page>
		<ion-content class="ion-padding">
			<h1>登入</h1>
			<form ref="login-form" @submit="login">
				<ion-item>
					<ion-input name="mobile" label="手機號碼" placeholder="e.g. 0912345678" required/>
				</ion-item>

				<ion-item>
					<ion-input name="password" label="密碼" type="password" required/>
				</ion-item>
				<ion-button expand="full" class="ion-margin-top" type="submit">
					登入
				</ion-button>
			</form>
		</ion-content>
	</ion-page>

	 <ion-alert :is-open="alertButtonShow"
		header="登入失敗"
		message="帳號或密碼錯誤,請再試一次。"
		:buttons="[{
				text: 'OK',
				role: 'confirm',
				handler: () => {
					alertButtonShow = false
				},
			}
		]" />
</template>
<template>
	<ion-page>
		<ion-content >
			<ion-header :translucent="true" >
				<ion-toolbar>
					<ion-title>登入成功!</ion-title>
				</ion-toolbar>
			</ion-header>

			<ion-button @click="logout">
				登出
			</ion-button>
		</ion-content>
	</ion-page>
</template>

理想狀況下,當我點下第一個畫面的登入按鈕,會跳到第二頁;第二頁的登出按鈕會跳回第一頁

但實際情況卻是前半段可以成功,但第二頁的登出按鈕一直沒有作用

Ionic 的筆記:Ionic 要連線 Web Request

本文內容都是以 Ionic + Vue 為前題撰寫