我看了视频后,想着写一个后台管理页面
我laravel里routes里面的配置如下:
Route::get('/admin','Admin\HomeController@index')->name('adminindex');
控制器代码如下:
namespace App\Http\Controllers\Admin;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class HomeController extends BaseController
{
public function index()
{
return view('admin/index');
}
}
webpack.mix.js代码如下:
let mix = require('laravel-mix');
mix.js('resources/assets/js/admin/main.js', 'public/js/admin')
.less('resources/assets/less/admin/main.less', 'public/css/admin');
main.js代码如下
import Vue from 'vue';
import VueRouter from 'vue-router';
import routers from './routers/router.js';
import iView from 'iview';
import 'iview/dist/styles/iview.css';
Vue.use(VueRouter);
Vue.use(iView);
const router = new VueRouter({
mode: 'history',
routers:routers
});
new Vue({
el: '#app',
router: router
});
router.js代码如下
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
export const login = {
path:'/',
component:'../view/login'
}
export const routers = {
login
}
login.vue代码如下
<style lang="less">
@import '../../..//less/login.less';
</style>
<template>
<div class="login" @keydown.enter="handleSubmit">
<div class="login-con">
<Card :bordered="false">
<p slot="title">
<Icon type="log-in"></Icon>
欢迎登录
</p>
<div class="form-con">
<Form ref="loginForm" :model="form" :rules="rules">
<FormItem prop="userName">
<Input v-model="form.userName" placeholder="请输入用户名">
<span slot="prepend">
<Icon :size="16" type="person"></Icon>
</span>
</Input>
</FormItem>
<FormItem prop="password">
<Input type="password" v-model="form.password" placeholder="请输入密码">
<span slot="prepend">
<Icon :size="14" type="locked"></Icon>
</span>
</Input>
</FormItem>
<FormItem>
<Button @click="handleSubmit" type="primary" long>登录</Button>
</FormItem>
</Form>
<p class="login-tip">输入任意用户名和密码即可</p>
</div>
</Card>
</div>
</div>
</template>
<script>
import Cookies from 'js-cookie';
export default {
data () {
return {
form: {
userName: 'iview_admin',
password: ''
},
rules: {
userName: [
{ required: true, message: '账号不能为空', trigger: 'blur' }
],
password: [
{ required: true, message: '密码不能为空', trigger: 'blur' }
]
}
};
},
methods: {
handleSubmit () {
this.$refs.loginForm.validate((valid) => {
if (valid) {
Cookies.set('user', this.form.userName);
Cookies.set('password', this.form.password);
this.$store.commit('setAvator', 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3448484253,3685836170&fm=27&gp=0.jpg');
if (this.form.userName === 'iview_admin') {
Cookies.set('access', 0);
} else {
Cookies.set('access', 1);
}
this.$router.push({
name: 'home_index'
});
}
});
}
}
};
</script>
<style>
</style>
在通过了cnpm run watch编译后,采用
http://www.****.cc/admin#/
进行访问的时候,试图文件里<router-view></router-view>
这里没有加载路由的vue文件,这个区域变成了<!---->
这是为什么呀??