Vue.component('nameofthecomponent',{ // options});
<html>
<head>
<title>Vue.js Component</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "component_test1">
<testcomponent></testcomponent>
</div>
<div id = "component_test2">
<testcomponent></testcomponent>
</div>
<script src="index.js"></script>
</body>
</html>
Vue.component('testcomponent',{
template : '<div><h1>This is a component example</h1></div>'
});
var vm = new Vue({
el: '#component_test1'
});
var vm1 = new Vue({
el: '#component_test2'
});
html, body {
margin: 5px;
padding: 0;
}
This is a component example
This is a component example
<div id = "component_test1">
<testcomponent></testcomponent>
</div>
<div id = "component_test2">
<testcomponent></testcomponent>
</div>
var vm = new Vue({
el: '#component_test1'
});
var vm1 = new Vue({
el: '#component_test2'
Vue.component('testcomponent',{
template : '<div><h1>This is a component example</h1></div>'
var vm = new Vue({
el: '#component_test1',
components:{
'testcomponent': {
template : '<div><h1>This is a component example</h1></div>'
}
}
});
<html>
<head>
<title>Vue.js Component</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "component_test1">
<testcomponent></testcomponent>
</div>
<div id = "component_test2">
<testcomponent></testcomponent>
</div>
<script src="index.js"></script>
</body>
</html>
Vue.component('testcomponent',{
template : '<div v-on:mouseover = "changename()" v-on:mouseout = "originalname();"><h1>This Custom Component is created by <span id = "name">{{name}}</span></h1></div>',
data: function() {
return {
name : "Panda"
}
},
methods:{
changename : function() {
this.name = "Alex";
},
originalname: function() {
this.name = "Panda";
}
}
});
var vm = new Vue({
el: '#component_test1'
});
var vm1 = new Vue({
el: '#component_test2'
});
template : '<div v-on:mouseover = "changename()" v-on:mouseout = "originalname();"><h1>This Custom Component is created by <span id = "name">{{name}}</span></h1></div>',
data: function() {
return {
name : "Panda"
}
<html>
<head>
<title>Vue.js Component</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "databinding">
<component v-bind:is = "view"></component>
</div>
<script type = "text/javascript">
var vm = new Vue({
el: '#databinding',
data: {
view: 'component1'
},
components: {
'component1': {
template: '<div><span style = "font-size:25;color:Blue;">This is a Dynamic Component Example</span></div>'
}
}
});
</script>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#databinding',
data: {
view: 'component1'
},
components: {
'component1': {
template: '<div><span style = "font-size:25;color:Blue;">This is a Dynamic Component Example</span></div>'
}
}
});
html, body {
margin: 5px;
padding: 0;
}
<component v-bind:is = "view"></component>
var vm = new Vue({
el: '#databinding',
data: {
view: 'component1'
},
components: {
'component1': {
template: '<div><span style = "font-size:25;color:red;">Dynamic Component</span></div>'
}
}
});