@@ -52,8 +52,8 @@ <h2 class="title">{{infos.title}}</h2>
52
52
const app = new Vue ( {
53
53
el : '#app' ,
54
54
data : {
55
- infos : info ,
56
- albums : json ,
55
+ infos : { } , // Khởi tạo rỗng
56
+ albums : { } , // Khởi tạo rỗng
57
57
} ,
58
58
computed : {
59
59
totalImages ( ) {
@@ -98,17 +98,26 @@ <h2 class="title">{{infos.title}}</h2>
98
98
}
99
99
} ,
100
100
async mounted ( ) {
101
- // Sử dụng fetch để lấy dữ liệu JSON
102
- const [ infoRes , albumsRes ] = await Promise . all ( [
103
- fetch ( './data/info.json' ) ,
104
- fetch ( './data/config.json' )
105
- ] ) ;
106
- this . infos = await infoRes . json ( ) ;
107
- this . albums = await albumsRes . json ( ) ;
108
-
109
- document . title = this . infos . name ;
110
- this . albumsCountAnimation ( ) ;
111
- this . initImgPreviewer ( ) ;
101
+ try {
102
+ // Nạp dữ liệu từ các tệp JSON
103
+ const [ infoRes , albumsRes ] = await Promise . all ( [
104
+ fetch ( './data/info.json' ) ,
105
+ fetch ( './data/config.json' )
106
+ ] ) ;
107
+
108
+ // Gán dữ liệu vào các thuộc tính Vue
109
+ this . infos = await infoRes . json ( ) ;
110
+ this . albums = await albumsRes . json ( ) ;
111
+
112
+ // Thiết lập tiêu đề trang
113
+ document . title = this . infos . name ;
114
+
115
+ // Chạy các chức năng bổ sung
116
+ this . albumsCountAnimation ( ) ;
117
+ this . initImgPreviewer ( ) ;
118
+ } catch ( error ) {
119
+ console . error ( 'Error loading JSON data:' , error ) ;
120
+ }
112
121
}
113
122
} ) ;
114
123
</ script >
0 commit comments