I watch the vue doc these day,and learning the component.
But there are one thing confusing me
the doc say there are some ways to registration a component
Vue.component('my-component', {
// options
})
var Child = {
template: '<div>A custom component!</div>'
}
new Vue({
// ...
components: {
// <my-component> will only be available in parent's template
'my-component': Child
}
})
these registration have defined the name of component(named 'my-component'),that is cool
but when i refered to some vue + webpack project, i found that they like to use below way to registration a component
index.html
<!--index.html-->
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test-vue</title>
</head>
<body>
<div id="root"></div>
<script src="./bundle.js"></script>
</body>
</html>
app.js
// app.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
import App from './App.vue'
Vue.use(VueRouter);
Vue.use(VueResource);
new Vue({
el: '#root',
render: (h) => h(App)
});
App.vue
<!--App.vue-->
<template>
<div id="app">
<div>Hello Vue</div>
</div>
</template>
<script>
export default {
}
</script>
it seem that the component do not descript its name, why the component still can work?
Please Help.
This is a new feature in ES6
var foo = 'bar';
var baz = {foo};
baz // {foo: "bar"}
// equal to
var baz = {foo: foo};
if directly assign App
to a object it variable name is the property name.