vue框架中HTML页面跳转到另一个界面了但是URL不变比说 http127001 我请求 http127001下面的uphtml网页上的url还是 http127001结合下面的代码给我具体的代码template div class=Polaris-Stack Polaris-Stack--distributionEqualSpacing Polaris-Stack--alignmentC
如果你想在vue框架中实现页面跳转但URL保持不变,可以使用vue-router插件来实现。下面是一个基本的示例代码:
<template>
<div>
<router-link :to="{ name: 'Dashboard' }">Dashboard</router-link>
<router-link :to="{ name: 'CheckoutZones' }">Checkout Zones</router-link>
<router-link :to="{ name: 'Funnels' }">Funnels</router-link>
<router-link :to="{ name: 'HelpCenter' }">Help Center</router-link>
<a data-polaris-unstyled="true" class="Polaris-Button" @click="toggleMore">
<span class="Polaris-Button__Content">
<span class="Polaris-Button__Text">More</span>
<span class="Polaris-Button__Icon">
<span class="Polaris-Icon">
<svg viewBox="0 0 20 20" class="Polaris-Icon__Svg" focusable="false" aria-hidden="true">
<path d="M5 8l5 5 5-5z" fill-rule="evenodd"></path>
</svg>
</span>
</span>
</span>
</a>
<div id="dropdownContent" class="dropdown-content" v-show="showMore">
<router-link :to="{ name: 'Payment' }">Payment</router-link>
<router-link :to="{ name: 'Pixel' }">Pixel</router-link>
</div>
</div>
</template>
<script>
export default {
data() {
return {
showMore: false
};
},
methods: {
toggleMore() {
this.showMore = !this.showMore;
}
}
};
</script>
在这个示例中,我们使用了<router-link>组件来实现页面跳转,通过设置to属性来指定目标路由。toggleMore方法用于切换更多设置的下拉菜单的显示和隐藏。
你还需要在Vue项目中安装并配置vue-router插件。在main.js中添加以下代码:
import VueRouter from 'vue-router';
import Dashboard from './components/Dashboard.vue';
import CheckoutZones from './components/CheckoutZones.vue';
import Funnels from './components/Funnels.vue';
import HelpCenter from './components/HelpCenter.vue';
import Payment from './components/Payment.vue';
import Pixel from './components/Pixel.vue';
Vue.use(VueRouter);
const routes = [
{ path: '/', redirect: '/dashboard' },
{ path: '/dashboard', name: 'Dashboard', component: Dashboard },
{ path: '/checkout-zones', name: 'CheckoutZones', component: CheckoutZones },
{ path: '/funnels', name: 'Funnels', component: Funnels },
{ path: '/help-center', name: 'HelpCenter', component: HelpCenter },
{ path: '/payment', name: 'Payment', component: Payment },
{ path: '/pixel', name: 'Pixel', component: Pixel }
];
const router = new VueRouter({
mode: 'history',
routes
});
new Vue({
router,
render: h => h(App)
}).$mount('#app');
这里我们定义了每个路由对应的组件,然后在routes数组中配置路由信息。{ path: '/', redirect: '/dashboard' }用于设置默认的路由。
最后,我们创建了一个Vue实例,并将router实例传递给它,并通过$mount()将Vue应用挂载到DOM元素上。
请注意,你需要在Vue项目中创建相应的组件文件(如Dashboard.vue、CheckoutZones.vue等),并在main.js中导入这些组件。
这样,当你点击链接或按钮时,页面将会显示对应的组件内容,同时URL将保持不变
原文地址: https://www.cveoy.top/t/topic/insg 著作权归作者所有。请勿转载和采集!