Skip to content

Instantly share code, notes, and snippets.

View 12cassie34's full-sized avatar

Cassie 12cassie34

View GitHub Profile
let A = 1
let B = 2
let C
function update() {
C = A + B
}
let A = 1
let B = 2
let C
C = A + B
console.log(C) // 3
A = 2
console.log(C) // still 3
@12cassie34
12cassie34 / example-4.js
Created February 25, 2022 06:40
Vuex v.s Pinia
import { theProfile } from './theProfile.js';
export default {
namespaced: true,
state: {
user: []
},
actions: {
recommendCourses() {
const theProfileStore = theProfile();
@12cassie34
12cassie34 / example-3.js
Last active February 25, 2022 06:35
Vuex v.s Pinia
// store/modules/theProfile.js
export default {
namespaced: true,
state: {
user: []
}
...
};
// store/modules/theCours.js
@12cassie34
12cassie34 / example-2.js
Last active February 11, 2022 07:27
Vuex v.s Pinia
const userStore = defineStore("userStore", {
state: () => {
return {
user: [],
};
},
actions: {
getNewUser() {
fetch('https://randomuser.me/api/')
.then((response) => {
@12cassie34
12cassie34 / example-1.js
Last active February 11, 2022 07:27
Vuex v.s Pinia
const store = createStore({
state: {
user: []
},
mutations: {
changeUser (state, newUser) {
state.user = newUser;
}
},
actions: {
@12cassie34
12cassie34 / vuePagination.vue
Created January 4, 2022 14:36
Vue Pagination - Step3-3
<select @change="parseItemsPerPage" v-model="itemsPerPage" name="dog-names" id="item-per-page">
<option value="1">1</option>
<option value="3">3</option>
<option value="5">5</option>
<option value="10">10</option>
</select>
@12cassie34
12cassie34 / vuePagination.vue
Created January 4, 2022 14:35
Vue Pagination - Step3-2
<div class="btn-group">
<button
v-for="pageNumber in totalPages"
@click="changeCurrentPage(pageNumber)"
>
{{ pageNumber }}
</button>
</div>
@12cassie34
12cassie34 / vuePagination.html
Created January 4, 2022 14:34
Vue Pagination - Step3-1
<ul>
<li v-for="(city, id) in currentContents" :key="id">
{{ city.name }}
</li>
</ul>
@12cassie34
12cassie34 / vuePagination.js
Created January 4, 2022 10:01
Vue Pagination - Step 2-5
computed: {
totalPages() {
return Math.ceil(this.dataAmount / this.itemsPerPage);
},
currentContents() {
if (!this.cities || this.cities.length != this.cities.length) {
return;
}
this.dataAmount = this.cities.length;