基于vue单页应用的例子

代码地址如下:
http://www.demodashi.com/demo/13374.html

目录结构

目录结构

  • src目录
    主要的代码目录
    • components
      存放项目组件
    • router
      路由文件
    • store
      store文件
    • main.js
      最终被打包到build文件
  • statics
    静态文件
  • idnex.html
    项目入口文件
  • webpack.config.js
    webpack配置文件

主要代码

入口index.html文件

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!-- 这meta的作用就是删除默认的苹果工具栏和菜单栏-->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <!-- 禁止识别电话号码-->
    <meta name="format-detection"content="telephone=no" />
    <title>心情手札</title>
    <link rel="shortcut icon" href="./favicon.ico">
    <link rel="stylesheet" type="text/css" href="./statics/reset.css">
    <link rel="stylesheet" type="text/css" href="./statics/vue-material.css">
    <link rel="stylesheet" type="text/css" href="./statics/iconfont/material-icons.css">
    <link rel="stylesheet" type="text/css" href="./statics/vue-swipe.css">
    <link rel="stylesheet" type="text/css" href="./statics/common.css">
</head>
<body>
    <div id="app"></div>
    <script src="./build/build.js"></script>
</body>
</html>

main.js文件

import Vue from 'vue';
import App from './App.vue';
import router from './router/index';
import store from './store/index';
import VueMaterial  from 'vue-material';
/*全局常量*/
global.API_PROXY = 'https://bird.ioliu.cn';
//注册主题
Vue.use(VueMaterial);
Vue.material.registerTheme('default', {
    primary: 'blue',
    accent: 'red',
    warn: 'red',
    background: 'white'
});

Vue.material.registerTheme('blue', {
    primary: 'blue',
    accent: 'red',
    warn: 'red',
    background: 'white'
});

Vue.material.registerTheme('teal', {
    primary: 'teal',
    accent: 'red',
    warn: 'red',
    background: 'white'
});

Vue.material.registerTheme('brown', {
    primary: 'brown',
    accent: 'red',
    warn: 'red',
    background: 'white'
});

Vue.material.registerTheme('indigo', {
    primary: 'indigo',
    accent: 'red',
    warn: 'red',
    background: 'white'
});

new Vue({
    router,
    store,
    el: '#app',
    render: h => h(App)
});

路由配置文件

import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
    base:'/sunnyNote/',
    routes:[
        {
            name:'home',
            path:'/home',
            component: require('../views/home/home.vue'),
            children:[
                {
                    name:'movie',
                    path:'/movie',
                    component:require('../components/movie/movie.vue')
                },
                {
                    name:'music',
                    path:'/music',
                    component:require('../components/music/music.vue')
                },
                {
                    name:'photo',
                    path:'/photo',
                    component:require('../components/photo/photo.vue')
                },
                {
                    name:'joke',
                    path:'/joke',
                    component:require('../components/joke/joke.vue')
                }
            ]
        },
        {path:'*',redirect:'./movie'}
    ]
});
export default router;

运行步骤

  1. 下载安装node
  2. 切换到根目录
  3. npm install
    安装所有的依赖包(第一次时)
  4. npm run dev
    开启dev-server服务
  5. 谷歌浏览器输入http://localhost:8080即可访问(手机模式预览)

运行效果

注意点

本项目是拿来作为vue单页项目学习使用,接口都来自第三方,不保证项目中的接口稳定(调用次数有限,网易云音乐地址已经不能播放)。发出来供大家学习参考,不足之处还望指正。

基于vue单页应用的例子

代码地址如下:
http://www.demodashi.com/demo/13374.html

注:本文著作权归作者,由demo大师代发,拒绝转载,转载需要作者授权

posted on   demo例子集  阅读(430)  评论(0编辑  收藏  举报

(评论功能已被禁用)
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示