Vue第三天,失败了,求解

问题:点击第一页第二页的东西都没有显示第一第二页的内容,只是导航栏的地址变了,第一页的链接点了但是没有变地址,压着command再点击会打开新的页面,导航的地址变为/first,但是也没有显示first页面

求大神指点~~

效果

点击第二页:

1、new Vue问题

问题不让用new开头

改正:

报错:

改正:

2、代码格式:

每一行后面都不需要“;”,写了会报错

代码如下:

App.vue

<template>

  <div id="app">

    <img src="./assets/logo.png">

    <h1>{{message}}</h1>

    <ul>

      <li><router-link to="/first">第一</router-link></li>

      <li><router-link to="/second">第二</router-link></li>

    </ul>

  </div>

</template>

 

<script>

export default {

  name: 'app',

  data () {

    return {

      message: 'hello world!'

    }

  },

  components: {}

}

</script>

 

<style>

#app {

  font-family: 'Avenir', Helvetica, Arial, sans-serif;

  -webkit-font-smoothing: antialiased;

  -moz-osx-font-smoothing: grayscale;

  text-align: center;

  color: #2c5047;

  margin-top: 60px;

}

</style>

 

 

main.js

// The Vue build version to load with the `import` command

// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'

import App from './App.vue'

import VueRouter from 'vue-router'

import VueResource from 'vue-resource'

import second from './components/second.vue'

// 开启debug模式

Vue.config.debug = true

Vue.use(VueRouter)

Vue.use(VueResource)

Vue.config.productionTip = false

 

// 义组, 也可以像教程之前教的方法从的文件引入

const First = { template: '<div><h2>我是第 1 个子</h2></div>' }

// 创建一个路由器实

// 并且配置路由规则

const router = new VueRouter({

  mode: 'history',

  base: __dirname,

  routes: [

    {

      path: '/first',

      components: First

    },

    {

      path: '/second',

      component: second

    }

  ]

})

 

const app = new Vue({

  el: '#app',

  router: router,

  components: { App },

  template: '<App/>'

})

 

Vue.use(

  {

    app

  }

)

 

 

second.vue

<template>

  <div id="second">

    <h1>I am a title.</h1>

    <a> written by {{ author }} </a>

  </div>

</template>

<script type="text/javascript">

export default {

  data () {

    return {

      author: 'Symiac'

    }

  }

}

</script>

<style>

</style>

 

webpack.config.js

var path = require('path')

var webpack = require('webpack')

 

module.exports = {

  entry: './src/main.js',

  output: {

    path: path.resolve(__dirname, './dist'),

    publicPath: '/dist/',

    filename: 'build.js'

  },

  module: {

    rules: [

      {

        test: /\.css$/,

        use: [

          'vue-style-loader',

          'css-loader'

        ],

      },      {

        test: /\.vue$/,

        loader: 'vue-loader',

        options: {

          loaders: {

          }

          // other vue-loader options go here

        }

      },

      {

        test: /\.js$/,

        loader: 'babel-loader',

        exclude: /node_modules/

      },

      {

        test: /\.(png|jpg|gif|svg)$/,

        loader: 'file-loader',

        options: {

          name: '[name].[ext]?[hash]'

        }

      }

    ]

  },

  resolve: {

    alias: {

      'vue$': 'vue/dist/vue.esm.js',

       vue: 'vue/dist/vue.js'

    },

    extensions: ['*', '.js', '.vue', '.json']

  },

  devServer: {

    historyApiFallback: true,

    noInfo: true,

    overlay: true

  },

  performance: {

    hints: false

  },

  devtool: '#eval-source-map'

}

 

if (process.env.NODE_ENV === 'production') {

  module.exports.devtool = '#source-map'

  // http://vue-loader.vuejs.org/en/workflow/production.html

  module.exports.plugins = (module.exports.plugins || []).concat([

    new webpack.DefinePlugin({

      'process.env': {

        NODE_ENV: '"production"'

      }

    }),

    new webpack.optimize.UglifyJsPlugin({

      sourceMap: true,

      compress: {

        warnings: false

      }

    }),

    new webpack.LoaderOptionsPlugin({

      minimize: true

    })

  ])

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值