Skip to content

Instantly share code, notes, and snippets.

View 12cassie34's full-sized avatar

Cassie 12cassie34

View GitHub Profile
@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-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-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();
let A = 1
let B = 2
let C
C = A + B
console.log(C) // 3
A = 2
console.log(C) // still 3
let A = 1
let B = 2
let C
function update() {
C = A + B
}
whenDepsChange(update)
const myFriendList = {
list: ["Pauline", "Ségoline", "Christina"],
get lastNewFriend() {
return this.list[this.list.length - 1]
},
set addNewFriend(newFriend) {
this.list.push(newFriend)
}
}
myFriendList.list.push("Rosalie")
const myName = ref('Cassie')
myName.value = 'Vanessa'
const target = {
message1: "hello",
message2: "everyone"
};
const handler = {
get(target, prop, receiver) {
return "world";
}
};