Git Product home page Git Product logo

stenciljs-vue's Introduction

Stencil component in Vue

This is a step by step guide, how we can use a stencil component in a Vue app. For more details you can also check the official Framework integration guide.

This project is created with Vue Cli

Similar guides

I have created another framework integration guide to use stencil components

In order to use the custom element library within the Vue app, the application must be modified to define the custom elements and to inform the Vue compiler which elements to ignore during compilation. This can all be done within the main.js file.

This example use the stencil component from the following project

Table of contents

Add the component to the dependencies

Add the component to the app dependencies in package.json

// package.json

"dependencies": {
  ...
  "@ranjeetsinghbnl/product-mgmt-stenciljs": "0.0.1"
}

or Install it npm install @ranjeetsinghbnl/product-mgmt-stenciljs

Import the component

import the component in the main.js file

import {
  applyPolyfills,
  defineCustomElements as defineProductMgmtExp
} from '@ranjeetsinghbnl/product-mgmt-stenciljs/loader';

Consume the component

Telling Vue to ignore the custom element tags see. Add the following code to your main.js file. You can also use the component names or regular expression for that.

Vue.config.ignoredElements = [/mf-\w*/];

or

Vue.config.ignoredElements = [
    'mf-product-view',
    'mf-product-cart'
];

and Bind the custom elements to the window object

applyPolyfills().then(() => {
  defineProductMgmtExp(window);
});

Using component

Now The components should then be available in any of the Vue components

You can use it

<mf-product-view></mf-product-view>
<mf-product-cart></mf-product-cart>

To know more about the components. Please check the Product & Cart showcase example

Note: I have include the bootstrap 4 css to give style to the stencil components. Because they are open to design changes. Their is no style added to components i have used in the showcase

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Run your tests

npm run test

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.

stenciljs-vue's People

Contributors

ranjeetsinghbnl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.