https://gitee.com/1981633/vue_study.git
源码下载地址,随笔记动态更新中

webpack.dev.conf.js中添加两段代码

  1. 'use strict'
  2. const utils = require('./utils')
  3. const webpack = require('webpack')
  4. const config = require('../config')
  5. const merge = require('webpack-merge')
  6. const path = require('path')
  7. const baseWebpackConfig = require('./webpack.base.conf')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const HtmlWebpackPlugin = require('html-webpack-plugin')
  10. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
  11. const portfinder = require('portfinder')
  12. //首先
  13. const express = require('express')
  14. const app = express()
  15. var appData = require('../data.json')
  16. var seller = appData.seller
  17. var goods = appData.goods
  18. var ratings = appData.ratings
  19. var apiRoutes = express.Router()
  20. app.use('/api', apiRoutes)
  21. const HOST = process.env.HOST
  22. const PORT = process.env.PORT && Number(process.env.PORT)
  23.  
  24. const devWebpackConfig = merge(baseWebpackConfig, {
  25. module: {
  26. rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
  27. },
  28. // cheap-module-eval-source-map is faster for development
  29. devtool: config.dev.devtool,
  30.  
  31. // these devServer options should be customized in /config/index.js
  32. devServer: {
  33. clientLogLevel: 'warning',
  34. historyApiFallback: {
  35. rewrites: [
  36. { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
  37. ],
  38. },
  39. hot: true,
  40. contentBase: false, // since we use CopyWebpackPlugin.
  41. compress: true,
  42. host: HOST || config.dev.host,
  43. port: PORT || config.dev.port,
  44. open: config.dev.autoOpenBrowser,
  45. overlay: config.dev.errorOverlay
  46. ? { warnings: false, errors: true }
  47. : false,
  48. publicPath: config.dev.assetsPublicPath,
  49. proxy: config.dev.proxyTable,
  50. quiet: true, // necessary for FriendlyErrorsPlugin
  51. watchOptions: {
  52. poll: config.dev.poll,
  53. },
  54. before(app) {
  55. app.get('/api/seller', (req, res) => {
  56. res.json({
  57. // 这里是你的json内容
  58. errno: 0,
  59. data: seller
  60. })
  61. }),
  62. app.get('/api/goods', (req, res) => {
  63. res.json({
  64. // 这里是你的json内容
  65. errno: 0,
  66. data: goods
  67. })
  68. }),
  69. app.get('/api/ratings', (req, res) => {
  70. res.json({
  71. // 这里是你的json内容
  72. errno: 0,
  73. data: ratings
  74. })
  75. })
  76. }
  77. },
  78. plugins: [
  79. new webpack.DefinePlugin({
  80. 'process.env': require('../config/dev.env')
  81. }),
  82. new webpack.HotModuleReplacementPlugin(),
  83. new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
  84. new webpack.NoEmitOnErrorsPlugin(),
  85. // https://github.com/ampedandwired/html-webpack-plugin
  86. new HtmlWebpackPlugin({
  87. filename: 'index.html',
  88. template: 'index.html',
  89. inject: true
  90. }),
  91. // copy custom static assets
  92. new CopyWebpackPlugin([
  93. {
  94. from: path.resolve(__dirname, '../static'),
  95. to: config.dev.assetsSubDirectory,
  96. ignore: ['.*']
  97. }
  98. ])
  99. ]
  100. })
  101.  
  102. module.exports = new Promise((resolve, reject) => {
  103. portfinder.basePort = process.env.PORT || config.dev.port
  104. portfinder.getPort((err, port) => {
  105. if (err) {
  106. reject(err)
  107. } else {
  108. // publish the new Port, necessary for e2e tests
  109. process.env.PORT = port
  110. // add port to devServer config
  111. devWebpackConfig.devServer.port = port
  112.  
  113. // Add FriendlyErrorsPlugin
  114. devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
  115. compilationSuccessInfo: {
  116. messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
  117. },
  118. onErrors: config.dev.notifyOnErrors
  119. ? utils.createNotifierCallback()
  120. : undefined
  121. }))
  122.  
  123. resolve(devWebpackConfig)
  124. }
  125. })
  126. })

添加Header.vue

  1. <template>
  2. <div class="header">
  3. 我是header
  4. </div>
  5. </template>
  6.  
  7. <script>
  8. export default {
  9. name: 'header.vue'
  10. }
  11. </script>
  12.  
  13. <style scoped>
  14.  
  15. </style>

App.vue

  1. <template>
  2. <div id="app">
  3. <v-header></v-header>
  4. <div class="tab">
  5. I am tab
  6. </div>
  7. <img src="./assets/logo.png">
  8. <router-view/>
  9. </div>
  10. </template>
  11.  
  12. <script>
  13. import VHeader from './components/header/header.vue'
  14. export default {
  15. components: {
  16. VHeader
  17. }
  18. }
  19.  
  20. </script>
  21.  
  22. <style>
  23. #app {
  24. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  25. -webkit-font-smoothing: antialiased;
  26. -moz-osx-font-smoothing: grayscale;
  27. text-align: center;
  28. color: #2c3e50;
  29. margin-top: 60px;
  30. }
  31. </style>

VHeader是系统推荐的写法。

运行结果

VUE2.0 饿了吗视频学习笔记(二):新版本添加路由和显示Header的更多相关文章

  1. VUE2.0 饿了吗视频学习笔记(四):颜色、跳转、设置、vue-resource

    https://gitee.com/1981633/vue_study.git 源码下载地址,随笔记动态更新中 1.设置选中项颜色 <template> <div id=" ...

  2. VUE2.0 饿了吗视频学习笔记(七-终):compute,循环,flex,display:table

    一.star组件使用到了computed属性 computed相当于属性的一个实时计算,当对象的某个值改变的时候,会进行实时计算. computed: { starType() { return 's ...

  3. VUE2.0 饿了吗视频学习笔记(六):定位问题、文字显示、模糊背景图片、点击事件

    一.定位问题按照视频写代码时,发现元素“5个“”定位不对,如下图 正常位置为 还以为是哪里写错了,仔细研究了下,需要在父div上加relative. position:relative/absolut ...

  4. VUE2.0 饿了吗视频学习笔记(一):VUE示例data.json

    https://gitee.com/1981633/vue_study.git 源码下载地址,随笔记动态更新中有的同学找不到data.json,以下是data.json内容 { "selle ...

  5. VUE2.0 饿了吗视频学习笔记(五):父子对象传递、显示图片

    一.父子组件之间对象传递 1.app.Vue中的v-header 中加入 v-bind:seller="seller" template> <div id=" ...

  6. VUE2.0 饿了吗视频学习笔记(三):VUE2.0取消了v-link

    https://gitee.com/1981633/vue_study.git 源码下载地址,随笔记动态更新中 写法如下 <div class="tab-item"> ...

  7. vue2.0 饿了么项目学习总结

    最近在GitHub上发现一个基于vue2.0的饿了么项目.本着互联网的分享精神,现在将我自己所理解的,所总结的经验分享给大家.本篇文字我将从学习的角度向大家分享. 在学习本项目之前我已经将vue2.0 ...

  8. Asp.net core 2.0.1 Razor 的使用学习笔记(五)

    按说这里应该写关于Role角色类的笔记,但是我还没时间实验这块,所以等以后我搞定了再来分享.现在先写其他部分. Asp.net core 2.0.1 Razor 的使用学习笔记——建立模型 按照微软官 ...

  9. Asp.net core 2.0.1 Razor 的使用学习笔记(六)

    Asp.net core 2.0.1 Razor 的使用学习笔记——基本页面的建立 VS这版(vs版本:15.5.6  .net版本:4.7.02558)的Razor页面自动生成就是坑爹货,它自动生成 ...

随机推荐

  1. Wireshark协议分析工具应用

    一.Wireshark简介与安装 Wireshark(前称Ethereal)是一个网络封包分析软件.网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料.Wireshark使用W ...

  2. Python——多进程

    进程的实例 # -*- coding:UTF-8 -*- import os import time from multiprocessing import Process #进程 def func( ...

  3. BZOJ1785[USACO 2010 Jan Gold 3.Cow Telephones]——贪心

    题目描述 奶牛们建立了电话网络,这个网络可看作为是一棵无根树连接n(1 n 100,000)个节点,节点编号为1 .. n.每个节点可能是(电话交换机,或者电话机).每条电话线连接两个节点.第i条电话 ...

  4. BZOJ4034[HAOI2015]树上操作——树链剖分+线段树

    题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中所有点的点权都 ...

  5. Js 百分比进度条

    [构想] CSS3 + JS CSS3控制进度 利用CSS3中的 @keyframes JS实现百分比 根据CSS来调整,时间 [页面代码] 第一种: 默认直接进入就是下载 CSS代码 body { ...

  6. hdu 3949 XOR (线性基)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=3949 题意: 给出n个数,从中任意取几个数字异或,求第k小的异或和 思路: 线性基求第k小异或和,因为题 ...

  7. 在finally块中使用try catch,并且catch的时候抛出异常的一个问题

    在finally中使用try/catch,并且catch的时候抛出异常 IDEA会提示警告 Reports throw statements inside of finally blocks. Whi ...

  8. MT【19】舒尔不等式设计理念及证明

    评:舒尔的想法是美妙的,当然他本身也有很多意义,在机械化证明的理念里,它也占据了一方田地.

  9. 使用metasploit中Evasion模块

    简介 几天前我说了kali这次更新我最关心的是metasploit升级到了5.0,5.0中有一个新的模块叫Evasion模块,这个模块可以轻松的创建反杀毒软件的木马,今天我们就来试一试 操作 首先打开 ...

  10. 【BZOJ5019】[SNOI2017]遗失的答案(FWT,动态规划)

    [BZOJ5019][SNOI2017]遗失的答案(FWT,动态规划) 题面 BZOJ 题解 发现\(10^8\)最多分解为不超过\(8\)个本质不同质数的乘积. 而\(gcd\)和\(lcm\)分别 ...