我遵循了本教程,在路由器中为多种布局添加元 它有效,但是布局内的组件不起作用
//更新//在DevTools中,我看不到组件,只是布局 这是我的代码
App.vue
<div id="app">
<component :is="this.$route.meta.layout || 'div'">
<router-view />
</component>
</div>
</template>
<script>
export default {
}
</script>
<style lang="scss">
</style>
router / index.js
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import weappLayout from '../layouts/webappLayout.vue'
import noLayout from '../layouts/no-layout.vue'
import signIN from '../views/sign-in.vue'
Vue.use(VueRouter);
const routes = [
{
path: '/',
name: 'Home',
component: Home,
meta: { layout: weappLayout }
},
{
path: '/login',
name: 'sign-in',
component: signIN,
meta: { layout: noLayout }
},
];
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes
});
export default router;
如果需要查看组件,请告诉我,谢谢您<3
sign.invue
<template>
<div>
<form class="form-signin">
<img
class="mb-4"
src=""
alt=""
width="72"
height="72"
/>
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail" class="sr-only">Email address</label>
<input
type="email"
id="inputEmail"
class="form-control"
placeholder="Email address"
required
autofocus
/>
<label for="inputPassword" class="sr-only">Password</label>
<input
type="password"
id="inputPassword"
class="form-control"
placeholder="Password"
required
/>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me" /> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">
Sign in
</button>
<p class="mt-5 mb-3 text-muted">© 2017-2020</p>
</form>
</div>
</template>
<script>
export default {
name: "sign-in"
};
</script>
<style >
html,
body {
height: 100%;
}
body {
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.form-signin .checkbox {
font-weight: 400;
}
.form-signin .form-control {
position: relative;
box-sizing: border-box;
height: auto;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>
Home.vue
<template>
<div class="home">
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: "Home",
components: {
}
};
</script>
答案 0 :(得分:0)
///最终解决了//
就是在布局模板中添加slot
标签
谢谢,