【发布时间】:2023-03-24 22:27:01
【问题描述】:
我正在尝试使用 vuejs 框架改造一个网站,我目前正在使用这个 boilerplate 来构建。我对 vuejs 非常陌生,比如 3 天的新手,我正在尝试弄清楚如何在我的 wordpress 网站上创建指向特定页面的链接。我成功地创建了指向不同组件的链接,但是我不知道如何为特定页面(如模板)创建组件并在 wordpress 上呈现该页面。
我当前组件的路由器看起来像这样--
import _ from "lodash";
import Vue from "vue";
import Router from "vue-router";
// Components
import Home from "../components/Home.vue";
import Post from "../components/Post/Post.vue";
import Page from "../components/Page/Page.vue";
import StatSearch from "../components/StatSearch.vue";
import CurrentShop from "../components/CurrentShop.vue";
import GameNews from "../components/GameNews.vue";
import UpcomingItems from "../components/UpcomingItems.vue";
import Challenges from "../components/Challenges.vue";
Vue.use(Router);
const router = new Router({
routes: [
{
path: "/",
name: "Home",
component: Home
},
{
path: "/CurrentShop",
name: "CurrentShop",
component: CurrentShop
},
{
path: "/Challenges",
name: "Challenges",
component: Challenges
},
{
path: "/UpcomingItems",
name: "UpcomingItems",
component: UpcomingItems
},
{
path: "/GameNews",
name: "GameNews",
component: GameNews
},
{
// Assuming you're using the default permalink structure for posts
path: "/:year/:month/:day/:postSlug",
name: "Post",
component: Post
},
{
path:
"/:pageSlug",
name: "Page",
component: Page
}
,
],
mode: "history",
base: "",
// Prevents window from scrolling back to top
// when navigating between components/views
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else {
return { x: 0, y: 0 };
}
}
});
router.afterEach((to, from) => {
// Add a body class specific to the route we're viewing
let body = document.querySelector("body");
let bodyClasses = body.className.split(" ");
if (bodyClasses.length > 0) {
const newBodyClasses = bodyClasses.filter(theClass =>
theClass.startsWith("vue--page--")
);
}
const slug = _.isEmpty(to.params.postSlug)
? to.params.pageSlug
: to.params.postSlug;
body.classList.add("vue--page--" + slug);
});
export default router;
这些链接的标题和往常一样 -
<li><router-link class="nav-link" to="/CurrentShop">Current Shop</router-link></li>
如何调用最初使用自定义 php 模板的页面?
【问题讨论】:
标签: php wordpress vue.js vuejs2