GithubHelp home page GithubHelp logo

keepfur / vue-router-express Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 9to6/vue-router-express

0.0 1.0 0.0 335 KB

Vuejs + Vue-router + express

License: MIT License

JavaScript 90.22% HTML 3.08% CSS 0.37% Vue 6.34%

vue-router-express's Introduction

Vuejs + nodejs + express History mode

I'm frontend javascript beginner using npm.
I write this example project as I want to get easist simple project to learn vuejs.

Prerequisite

Usage

create example directory

$ mkdir test_route_express

nodejs express settings

Reference document

$ cd backend
$ npm install
$ DEBUG=backend:* npm start

Check npm start
http://localhost:3000

vuejs settings

install

$ vue init webpack frontend
# Enter informations on the prompt
# Must enter 'Y' about the question 'vue-router'
$ cd frontend
$ npm install
$ npm run dev

Check npm run dev http://localhost:8080

Frontend settings

  1. Remove this lines on this file, frontend/config/index.js
...
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
...
  1. And add this lines
...
index: path.resolve(__dirname, '../../backend/public/index.html'),
assetsRoot: path.resolve(__dirname, '../../backend/public'),
...
  1. Add new component

frontend/src/components/Second.vue

<template>
  <div>
    <h1>Second page</h1>
    
  </div>
</template>

<script>
export default {
  created: function () {
    console.log('created')
  },
  data: function () {
    return {
      movie: {}
    }
  }
}
</script>
  1. Change content on this file, frontend/src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Second from '@/components/Second'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'Hello',
      component: Hello
    },
    {
      path: '/second',
      name: 'Second',
      component: Second
    }
  ]
})

  1. npm build

Now you have to compile vuejs

$ cd frontend
$ npm run build

You can see index.html file in public directory.

nodejs express settings again

  1. Remove this lines on this file, backend/routes/index.js
res.render('index', { title: 'Express' });
  1. And add this lines
res.sendFile(path.join(__dirname, '../public', 'index.html'))

Run

$ cd backend
$ DEBUG=backend:* npm start

Go to http://localhost:3000/second

vue-router-express's People

Contributors

9to6 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.