0

I use vue using cdn link and using my component just like this.

Vue.component('forward-button', {
  template: `
		<button type=button class="btn btn-default" @click="goURL">{{this.title}}</button>
	`,
  props: ['url', 'title'],
  methods: {
    goURL: function() {
      console.log(this.url);
      window.open(this.url);
    }
  }
});
new Vue({
  el: '#app',
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id='app'>
  <forward-button title="google" url="#"></forward-button>
</div>

How do I style this as the single file component? Don't want to use styling inside HTML

1 Answer 1

1

You can't use Single File Components when using vue through a cdn link.

You can use a CSS file imported at the <head> of your HTML file like a regular website.

Sign up to request clarification or add additional context in comments.

4 Comments

if I want to apply CSS only for this component what should I do? If I applied inside head then other elements can be affected
Use classes to style your elements, and make sure you separate the class names properly. BEM is a method for doing this, but others exist. css-tricks.com/bem-101 If you define your css in classes like forward-button__inner--default for example instead of btn-default, you're OK.
Just to be absolutely clear: what you're asking is impossible without a build step. Using Vue through a CDN means it's pre-built for you. You can't use component scoped CSS, only global CSS to style components defined this way. So either, you use global CSS in a way that you make classes for each component separately, or you install and build vue locally.
I do understand. Thanks a lot for helping. Highly Appriciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.