1.将vue3的router路由方式改成 createWebHashHistory方式,否则打包到thinkphp运行时会出现白屏现象
import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'
const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'login',
component: Login
},
{
path: '/main',
name: 'main',
component: Main
}
]
})
export default router
对vue3项目运行 yum run build ,把dist文件夹复制到thinkphp的public目录,
然后修改thinkphp的controller/index.php,强制跳转到/dist/index.html
<?php
namespace app\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
return redirect("dist/index.html");
}
}
修改thinkphp的route文件app.php
Route::get("/", "index/index");
设置完成 访问 网址就可以vue3的首页了。