File tree Expand file tree Collapse file tree 3 files changed +22
-23
lines changed
Expand file tree Collapse file tree 3 files changed +22
-23
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,13 @@ import store from "../stores";
2626export default {
2727 setup () {
2828 const state = reactive ({
29- // 页数
29+ // Page number
3030 page: 1 ,
31- // 列表数据
31+ // List data
3232 news: [],
33- // 通过搜索框的值去筛选后的新列表数据
33+ // Filtered list based on search value
3434 newsComputed: computed (() => {
35- // 判断是否输入框是否输入了筛选条件,如果没有返回原始的 news 数组
35+ // Return filtered news if search value exists, otherwise return all
3636 if (store .state .searchValue ) {
3737 return state .news .filter (item => {
3838 if (item .title .indexOf (store .state .searchValue ) >= 0 ) {
@@ -45,29 +45,28 @@ export default {
4545 }),
4646 searchValue: store .state
4747 });
48- // 发送 ajax 请求获取列表数据
48+ // Fetch list data via API
4949 const loadMore = async () => {
50- // 获取列表数据
51- let data = await axios .get (" https://cnodejs.org/api/v1/topics" , {
50+ const data = await axios .get (" https://cnodejs.org/api/v1/topics" , {
5251 params: {
53- // 每一页的主题数量
52+ // Topics per page
5453 limit: 10 ,
55- // 页数
54+ // Page number
5655 page: state .page
5756 }
5857 });
59- // 叠加页数
58+ // Increment page number
6059 state .page += 1 ;
6160 state .news = [... state .news , ... data .data .data ];
6261 };
6362 onMounted (() => {
64- // 首屏加载的时候触发请求
63+ // Load initial data on mount
6564 loadMore ();
6665 });
6766 return {
68- // 让数据保持响应式
67+ // Keep data reactive
6968 ... toRefs (state),
70- // 查看更多事件
69+ // Load more event handler
7170 loadMore
7271 };
7372 }
Original file line number Diff line number Diff line change 2626import { reactive , toRefs , watch } from " @vue/composition-api" ;
2727import store from " ../stores" ;
2828export default {
29- // setup相当于2.x版本的beforeCreate生命周期
29+ // setup() is equivalent to beforeCreate lifecycle in Vue 2.x
3030 setup () {
31- // reactive() 函数接收一个普通对象,返回一个响应式的数据对象
31+ // reactive() takes a plain object and returns a reactive data object
3232 const state = reactive ({
3333 searchValue: " " ,
34- // 搜索框两个状态,聚焦和非聚焦
34+ // Search bar states: focused and unfocused
3535 isFocus: false ,
3636 inputElement: null
3737 });
38- // 切换搜索框状态的方法
38+ // Toggle search bar focus state
3939 const toggle = () => {
40- // 让点击搜索后出现的输入框自动聚焦
40+ // Auto-focus the input when search is activated
4141 state .inputElement .focus ();
4242 state .isFocus = ! state .isFocus ;
4343 };
44- // 监听搜索框的值
44+ // Watch search input value
4545 watch (
4646 () => {
4747 return state .searchValue ;
4848 },
4949 () => {
50- // 存储输入框到状态 store 中心,用于组件通信
50+ // Store search value in centralized store for cross-component communication
5151 store .setSearchValue (state .searchValue );
5252 }
5353 );
5454 return {
55- // 将 state 上的每个属性,都转化为 ref 形式的响应式数据
55+ // Convert each state property to ref for reactivity
5656 ... toRefs (state),
5757 toggle
5858 };
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ export default {
22 state : {
33 searchValue : ""
44 } ,
5- // 设置搜索框的值
5+ // Set search value
66 setSearchValue ( value ) {
77 this . state . searchValue = value
88 } ,
9- // 获取搜索框的值
9+ // Get search value
1010 getSearchValue ( ) {
1111 return this . state . searchValue
1212 }
You can’t perform that action at this time.
0 commit comments