Vite 的Pwa功能是在web情況下,開發web就能製作成App的效果,不需要上架app store / google play 也不需要使用安裝 exe檔案,只需要連結就能增加的手機畫面, Vite PWA Vite 和生態系統的 PWA 整合零配置和與框架無關的 Vite PWA 插件 做好了網站以後,執行以下指令:
import { describe, it, expect } from 'vitest' import { mount } from '@vue/test-utils' import Nav from '../Nav.vue'
describe('Nav.vue gets the following array from the parent element frontLayout.vue', () => { const navLists = [ { id_set: '001', title: '出勤打卡', href: '/' }, { id_set: '002', title: '出勤設定', href: '/set_check' }, { id_set: '003', title: '出勤列表', href: '/work_check_lists' }, { id_set:'004', title:'出勤行事曆', href:'/work_calendar'} ] const pageNameActive = '001'; const wrapper = mount(Nav, { props: { navLists: navLists, pageNameActive:pageNameActive } }) it('Is navLists data correctly rendering information? ', () => { const items = wrapper.findAll('li'); expect(items.length).toBe(4); expect(items[0].text()).toBe('出勤打卡'); expect(items[1].text()).toBe('出勤設定'); expect(items[2].text()).toBe('出勤列表'); expect(items[3].text()).toBe('出勤行事曆'); }); it('pageNameActive is rendered when the initial value is passed', () => { expect(pageNameActive).toMatch(pageNameActive); })
it('Emits the event of the current data when clicked', () => { const items = wrapper.findAll('li'); const button = wrapper.find('li'); button.trigger('click'); expect(pageNameActive).toMatch(items[0].id_set); expect(pageNameActive).toMatch(items[1].id_set) expect(pageNameActive).toMatch(items[2].id_set) expect(pageNameActive).toMatch(items[3].id_set) expect(button.find('li.isActive')); }) //emitted ,toHaveProperty 點擊時取出當筆數據的事件 it('Event to retrieve the current data when clicked', async () => { await wrapper.get('[data-test="button"]').trigger('click') expect(wrapper.emitted()).toHaveProperty('sendMenuClickActive') }) })
import { createSSRApp } from 'vue' import App from './App.vue'
// SSR requires a fresh app instance per request, therefore we export a function //每個請求都需要一個新的應用程式實例,因此我們匯出一個函數 // that creates a fresh app instance. If using Vuex, we'd also be creating a // fresh store here.
const SumFor=(arr)=>{ var sum=0; for (var i = 0; i < arr.length; i++) { sum += arr[i]; }; return sum; } var data= [1, 1, 1]; console.log(SumFor(data));
forEach遍歷 加總
1 2 3 4 5 6 7 8 9
const sumforEach = (arr) =>{ var sum=0; arr.forEach((el)=>{ sum+=el; }); return sum; } var data= [1, 1, 1]; console.log(sumforEach(data));
reduce() 方法將一個累加器及陣列中每項元素(由左至右)傳入回呼函式,將陣列化為單一值。
1 2 3 4
var sum = [1, 1, 1].reduce( (a, b)=> { return a + b; }, 0); console.log(sum);