Tôi mới vào Vue.js và muốn sử dụng các thành phần tệp đơn, nhưng tôi không hiểu quy trình làm việc.Vue.js tải thành phần một thành phần
Ví dụ, tôi có ba thành phần: App
, Grid
và List
App.vue
<template>
<div id="app">
<div id="grid"></div>
<div id="right"></div>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {
message: 'Hello Vue!'
}
}
}
</script>
Grid.vue
<template>
<div id="left"></div>
</template>
<script>
export default {
name: 'grid',
data: function() {
return {
grid: 'some-data'
}
}
}
</script>
List.vue
<template>
<div id="right"></div>
</template>
<script>
export default {
name: 'list',
data: function() {
return {
text: 'some-text'
}
}
}
</script>
Main.js
import Vue from 'vue'
import App from './vue/App.vue'
import Grid from './vue/Grid.vue'
import PatternList from './vue/PatternList.vue'
new Vue({
el: '#app',
render: h => h(App)
});
new Vue({
el: '#grid',
render: h => h(Grid)
});
new Vue({
el: '#right',
render: h => h(PatternList)
});
Nó hoạt động nhưng tôi hy vọng đây không phải là cách đúng đắn để tạo các thành phần lồng nhau.
Có ai có thể cho biết cách thực hiện không? Cảm ơn
Cảm ơn rất nhiều! Đó là những gì tôi đang tìm kiếm. – Dmitry