GithubHelp home page GithubHelp logo

syedpeer / php-vue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aryelgois/php-vue

0.0 2.0 0.0 79 KB

Webapp skeleton using PHP and Vue.js

License: MIT License

PHP 20.77% Vue 7.30% JavaScript 71.93%

php-vue's Introduction

Bundling Vue.js components with webpack for use in PHP applications

Based on post by Michał Męciński: Using Vue.js components in PHP applications

Intro

This repository is intended to be a skeleton for new PHP projects using Vue.js in the front-end.

Setup

  1. You may clone this repository and go to step 2, or you can:
# create a new repository
git init
# create repository manifest files
touch LICENSE README.md
# add a Initial commit
git add .
git commit -m 'Initial commit'
# [optional] change to a development branch
git checkout -b develop
# add this repository remote and fetch its data
git remote add aryelgois/php-vue https://github.com/aryelgois/php-vue.git
git fetch aryelgois/php-vue
# merge squash
git merge --squash aryelgois/php-vue/master -X ours # --allow-unrelated-histories (for git >2.9)
git commit # Title: 'Import aryelgois/php-vue', Body: Squash log git writes in commit editor
  1. Install dependencies
cd webpack
npm install

Usage

Development

It is recommended to use the webpack-dev-server with the hot module replacement for a better experience:

cd webpack
npm run dev

It will be using http://localhost:8080 to serve the required files. Apache might be running on port 80, but there is a configuration telling the browser not to block the AJAX requests to 8080.

Production

Generate minified files for production:

cd webpack
npm run build

They are placed at public/assets/, so configure PHP to use them in the pages. The example automatially use them if assets.json exists.

The production server does not need the webpack/ directory.

Workflow

Root component

Since the Vue runtime-only build is being used, you can not include templates in the HTML or in JavaScript. They must be in *.vue files, compiled by webpack.

So, you create a root component for your application and use webpack/main.js to render it. e.g.:

// ...

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

And you can not target the <body>, because the target element is replaced by the component. Use a child element to fill the whole body. Also, the <script> including the bundle needs to be after such element.

New components

Create Single File Components in webpack/components/ and add them in webpack/main.js:

// ...
import MyComponent from './components/MyComponent.vue';

// ...
Vue.component('my-component', MyComponent);

// ...

Comunication with PHP

Use AJAX to exchange data with the PHP server, with vue-resource.

php-vue's People

Contributors

aryelgois avatar

Watchers

 avatar  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.