Code Monkey home page Code Monkey logo

http-vue-loader's Introduction

http-vue-loader

Load .vue files directly from your html/js. No node.js environment, no build step.

examples

my-component.vue

<template>
	<div class="hello">Hello {{who}}</div>
</template>

<script>
module.exports = {
	data: function() {
		return {
			who: 'world'
		}
	}
}
</script>

<style>
.hello {
	background-color: #ffe;
}
</style>

myFile.html

using httpVueLoader()

...
<script type="text/javascript">

	new Vue({
		components: {
			'my-component': httpVueLoader('my-component.vue')
		},
		...

or, using httpVueLoaderRegister()

...
<script type="text/javascript">

	httpVueLoaderRegister(Vue, 'my-component.vue');

	new Vue({
		components: [
			'my-component'
		},
		...

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest Latest ? ? Latest 9+

Dependances

API

httpVueLoader(url)

url: any url to a .vue file

httpVueLoaderRegister(vue, url)

vue: a Vue instance
url: any url to a .vue file

How it works

  1. http request the vue file
  2. load the vue file in a document fragment
  3. process each section (template, script and style)
  4. return a promise to Vue (async components)

Notes

The aim of http-vue-loader is to quickly test .vue components without any compilation step.
However, for production, I recommend to use webpack module bundler with vue-loader, see also why Vue.js doesn't support templateURL.
Note also that http-vue-loader only supports text/x-template for <template>, text/javascript for <script> and text/css for <style>

Caveat

Due to the lack of suitable API in Google Chrome and Internet Explorer, syntax errors in the <script> section are only reported on FireFox.

Credits

Franck Freiburger

http-vue-loader's People

Contributors

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