Giter VIP home page Giter VIP logo

vue-typed's Introduction

VueTyped

vue-typed

VueTyped contains sets of ECMAScript / Typescript decorators that helps you write Vue component easily.

npm version Build status Build Status GitHub issues GitHub license

What is this for?

Normaly you wrote Vue application like this:

new Vue({
  template: 
  `<div>
    <input type="text" v-model="message">
    <button v-on:click="clear">Clear</button>
    <div>{{status}}</div>
  </div>`,
  data: function() {
    return {
      message: 'Hello!'
    }
  },
  computed: {
    status: function() {
      return this.message.length < 15 ? 'Too short... type some more...' : 'Alright, stop typing now..'
    }
  },
  methods: {
    clear: function() {
      this.message = ''
    }
  }
}).$mount('#app')

See live demo here

It could be mess if you bring the code above in Typescript world. The usage of keyword this could lead unexpected error. VueTyped makes you possible to write Vue with Typescript or ES6 with no hassle. VueTyped insipired by vue-class-component.

With VueTyped you'll write code above in Typescript like this:

import * as Vue from 'vue'
import { Component } from 'vue-typed'

@Component({
  template: `
  <div>
    <input type="text" v-model="message">
    <button v-on:click="clear">Clear</button>
    <div>{{status}}</div>
  </div>`,
}) 
class App extends Vue {
  message:string = 'Hello!'
  
  get status() {
    return this.message.length < 15 ? 'Too short... type some more...' : 'Alright, stop typing now..'
  }
  
  clear() {
    this.message = ''
  }
}

new App().$mount('#app')

See live demo here

Installation

NPM

$ npm install vue-typed

Bower

$ bower install vue-typed

CLI

If you are start with a new project, then it's good to use vue-typed-boilerplate to scaffold your new project. This boilerplate setup typescript project using webpack as the module bundler.

$ npm install -g vue-cli
$ vue init vue-typed/vue-typed-boilerplate my-project
$ cd my-project
$ npm install
$ npm start

Compatibility

Vue 2.0 or above

For older Vue supports please refer to VueTyped 2.0.1.

Typescript 2.2.2 or above

License

MIT

vue-typed's People

Contributors

adionob avatar budiadiono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-typed's Issues

vuetify v-data-table 's data when provided using vue-typed throws missing props error

Trying to use Vuetify's data table. Upon emulating what is provided in the sample using vue-typed, I get the following error

vue.runtime.esm.js?a427:475 [Vue warn]: Property or method "props" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

data.vue

<template>
    <v-content>
        <v-data-table
        v-bind:headers="headers"
        :items="items"
        class="elevation-1"
        hide-actions
        dark
      >
      <template slot="items" slot-scope="props">
        <td>{{ props.item.name }}</td>
        <td class="text-xs-right">{{ props.item.calories }}</td>
        <td class="text-xs-right">{{ props.item.fat }}</td>
        <td class="text-xs-right">{{ props.item.carbs }}</td>
        <td class="text-xs-right">{{ props.item.protein }}</td>
        <td class="text-xs-right">{{ props.item.sodium }}</td>
        <td class="text-xs-right">{{ props.item.calcium }}</td>
        <td class="text-xs-right">{{ props.item.iron }}</td>
      </template>
        </v-data-table>
    </v-content>
</template>

Ts file

import Vue from "vue";
import { Component } from "vue-typed";
let template = require("./data.vue");

@Component({
    mixins: [template],
})
export default class Inventory extends Vue {
    max25chars(v) {
        return v.length <= 25 || "Input too long!";
    }
    get tmp() {
        return "";
    }
    get search() { return ""; }
    get pagination() { return {}; }
    get headers() {
        return [
            {
                text: "Dessert (100g serving)",
                align: "left",
                sortable: false,
                value: "name"
            },
            { text: "Calories", value: "calories" },
            { text: "Fat (g)", value: "fat" },
            { text: "Carbs (g)", value: "carbs" },
            { text: "Protein (g)", value: "protein" },
            { text: "Sodium (mg)", value: "sodium" },
            { text: "Calcium (%)", value: "calcium" },
            { text: "Iron (%)", value: "iron" }
        ];
    }
    get items() {
        return [
            {
                value: false,
                name: "Frozen Yogurt",
                calories: 159,
                fat: 6.0,
                carbs: 24,
                protein: 4.0,
                sodium: 87,
                calcium: "14%",
                iron: "1%"
            },
            {
                value: false,
                name: "Ice cream sandwich",
                calories: 237,
                fat: 9.0,
                carbs: 37,
                protein: 4.3,
                sodium: 129,
                calcium: "8%",
                iron: "1%"
            }
        ];
    }
}

Is there something that am missing? to wire up in terms of vue-typed?

load stylesheet

sorry , I don't know how to load my stylesheet in a singe component

new boilerplate project fails to compile with Vue 2.5 and TS 2.7.2

Hi,
I'm trying to create a new project with the provided template.
Once created, when I try to start with npm start, I get this:

ERROR in /Users/ajo/Temp/repos/vue-typed-project/node_modules/vue-typed/dist/lib/mixins-global.d.ts
(10,64): error TS2709: Cannot use namespace 'Vue' as a type.

ERROR in /Users/ajo/Temp/repos/vue-typed-project/node_modules/vue-typed/dist/lib/options.d.ts
(11,60): error TS2709: Cannot use namespace 'Vue' as a type.

ERROR in /Users/ajo/Temp/repos/vue-typed-project/node_modules/vue-typed/dist/lib/component.d.ts
(10,62): error TS2709: Cannot use namespace 'Vue' as a type.
webpack: Failed to compile.

Any idea ?

thanks,
BR

Vuex Store Namespacing

Hey, is there a way to get the vuex module namespacing working with vue-typed?

I have a store with an auth module with enabled namespace. When I try to access it using:

this.$store.auth.token

I always get the Property 'auth' does not exist on type 'Store<any>'. error.

How use styles?

Hello. I am trying to add styles to component like a

@Component({
   template: `
 <div>
   <input class="my-style" type="text" v-model="message">
   <button @click="clear">Clear</button>
   <div>{{status}}</div>
   </div>
   
   <style>
.my-style {
 width: 100px;
 padding: 10;
}
</style>`
})
export class Container extends Vue {...

But it doesn't work.
How i can add style for component?

SSR Support with template option

As stated in the official documentation:

The standalone build includes the compiler and supports the template option. It also relies on the presence of browser APIs so you cannot use it for server-side rendering.

The template option is not supported with SSR, which means that we cannot construct components with typescript like the following:

@Component({ 
  template: '<span>da</span>'
})
class HomeComponent {
  message: string = 'hello'
}

Is there a solution to this problem?

ts error in index.d.ts

Hi, I have a TS error in index.d.ts:

Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.

Indeed, there's a missing return type in line 12 (for the new () construct):

export function Mixins<T>(...components: { new (); }[]): VirtualClass<T>

Vue-typed doesn't export modules

In order to enable tree-shaking / bundling (for bundlers like Rollup), it would be great if this library was published with source files.

Currently using with Rollup, it generates this error: Error: 'Mixin' is not exported by node_modules/vue-typed/dist/index.js

I was able to workaround this with npm i --save-dev https://github.com/vue-typed/vue-typed/tarball/v2.1.4

Additional div

Hi. I am trying simple example from https://github.com/vue-typed/vue-typed.
Template:

<input type="text" v-model="message">
<button v-on:click="clear">Clear</button>

When I start npm start
On source page I see additional DIV
"<div class="ginger-module-inputHandlerGhost ginger-module-inputHandlerGhost-textarea"></div>"
betwen divs
and button shows on the next line.

but when I build app - all ok. It souse code "ginger-module-inputHandlerGhost" remove and button shows how expected.

What I can to do with this?

iview: Property '$Message' does not exist

Hi, I try examples from iview (https://www.iviewui.com/components/message-en)

import {Component, Prop} from 'vue-typed'
import Vue from 'vue'

@Component({template: `<div>
    <Button type="primary" @click="modal1 = true">显示对话框</Button>
    <Modal
        v-model="modal1"
        title="普通的Modal对话框标题"
        @on-ok="ok"
        @on-cancel="cancel">
        <p>对话框内容</p>
        <p>对话框内容</p>
        <p>对话框内容</p>
    </Modal>
  </div>`})
export class CarsComponent extends Vue {
  modal1 : boolean = false;
  
  ok() {
    this.$Message.info('点击了取消');
  }

  cancel() {
    this.$Message.info('点击了取消');
  }
}

see compiler error:

ERROR in ./src/components/cars/cars.component.ts
(23,10): error TS2339: Property '$Message' does not exist on type 'CarsComponent'.

How I can fix it? Thks.

Missing some intellisense

I test converting component wrote in Js into Typescript, which is works fine.
Unfortunately its missing some intellisense, like 'created, methods, computed'

for example :

@Component({
    template: `
                <div>
                    <a class="cloud-package" v-bind:class="[activePackage == index ? 'active' : '']" v-for="(item, index) in packages" v-on:click="activated(index)">
					    <h2>{{ item.label }}</h2>
	    		    </a>
                </div>
            `,
    data() {
        return {
            packages: [
                { id: 1, label: 'AAA' },
                { id: 2, label: 'BBB' },
                { id: 3, label: 'CCC },
                { id: 4, label: 'DDD' }
            ],
            activePackage: null
        }
    },
    methods: {
        activated: function (item) {
            this.activePackage = item
        }
    }
})

Comparison with vue-property-decorator

Hi there,

I work on Vue+TS applications for almost a year now. Currently I'm using this library (https://github.com/kaorun343/vue-property-decorator) to get decorator helpers.

I just discovered vue-typed and it looks very similar, almost identical on certain details. I'm curious about the reason why you decided to make your own library for vue TS decorators. Could you make a comparison between the libraries ? It would be great if we could have a reference decorator library for Vue

Unexpected keyword const

When running "npm run dev" everything goes well for Chrome but in Safari I get the following message:
image

Any idea on how to fix this?

Add support for Events, Mixins and Filters

Good work on this project so far; however I've had to switch (for now) to vue-ts-decorate as it has support for Events and Mixins.

// Events
@On(eventName)
@Once(eventName)

// Mixins
@Mixin()

It would've been good if the author of vue-ts-decorate actually extended an existing project rather than creating his own; maybe that's something which can still happen.

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.