"^1.3"
настройка webpack:
mix.js('resources/assets/js/app-client.js', 'public/js')
.js('resources/assets/js/app-server.js', 'public/js')
.sass('resources/sass/app.scss', 'css/');
само приложение (точка входа) app.js
import App from './components/App.vue';
import Vue from 'vue';
import router from './router'
export default new Vue({
router,
render: h => h(App)
});
тестовый шаблон приложение App.vue
<template>
<div id="app">
<h1>{{ title }}</h1>
<router-view></router-view>
<router-link :to="{ name: 'about' }">About</router-link>
<router-link :to="{ name: 'contact' }">Contact</router-link>
</div>
</template>
<script>
export default {
data() {
return {
title: 'Welcome To My Site'
}
}
}
</script>
маршруты router.js :
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);
function PageComponent(name) {
return {
render: h => h('h3', Hello from the ${name} page)
};
}
export default new Router({
mode: 'history',
routes: [
{ path: '/', component: PageComponent('Home'), name: 'home' },
{ path: '/about', component: PageComponent('About'), name: 'about' },
{ path: '/contact', component: PageComponent('Contact'), name: 'contact' }
]
});
файл app-client.js :
import app from './../../js/app';
app.$mount('#app');
файл app-server.js :
import renderVueComponentToString from 'vue-server-renderer/basic';
import app from './../../js/app'
import router from './../../js/router';
new Promise((resolve, reject) => {
router.push(url);
router.onReady(() => {
const matchedComponents = router.getMatchedComponents();
if (!matchedComponents.length) {
return reject({ code: 404 });
}
resolve(app);
}, reject);
}).then(
app => {
renderVueComponentToString(app, (err, res) => {
dispatch(res);
});
})
.catch((err) => {
dispatch(err);
});
подключаю в app.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Scripts -->
<link rel="icon" href="{{ asset('image/favicon.png') }}" type="image/x-icon" />
<script defer src="{{ mix('js/app-client.js') }}"></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
{!! ssr('js/app-server.js')->render() !!}
</div>
</body>
</html>
VUE работает - рендеринга не вижу - возможно , кто сталкивался с подобным подскажите куда копать ?
Вылей хотяб на pastebin
Обсуждают сегодня