Subscribe on changes!

Pinia bug? Report

avatar
Aug 11th 2023

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNrtV01v4zYQ/SusLlYA2wKyPTlOsLtFDi2222A/bgICRaJl7kqkQFJeB4b/e4dDUaK+7KLYW+sgFsU38zicmUfJp+BdVa0PNQ02wVbTsioSTR9iTsj2l9Vqy8qcKJnex8F6HSVKUa2iF5V/ELlYVzyPgweyWlnzjB1IWoANGCugUXtADdJgLAOA8Z2Q5ReqNIDVXnD6zOvyhUoC80TD/DYCY9/PcTKuqDRuFgOU8arWRL9WFGBNjwCSw6oUGS1gwmcHIHKcc/xKJ336/a8PpxMpVU7O520Edy3yUmstOHmbFiz97ly/Ksbzz1pICqvhZnH6PdoCL949SbFjBd1GluJaTIXImfHtYrptYrq1Qd1eCQoKZQhsPMjWjwfx2WjcaBt5nQG3KpWs0jBmZSWkJidSK/oVyoPbJ2eyk6Ik2DPKzEQAW2z9TcXBneco6a6zhzZE1PzRI1pkdJfUBVjGUH5dV+GNGZowU8GVJr0eujd0YRzEwQ2wdEbt8mDhRxoaM2sogVxyCMgnXHqeZ2Q8L41DSfVeZGpjQxlUv4uQEL1nat1tHi1DnPSXccEacnO13119LjBiSa8xmm8T/jZqChcsA60gNTuWQ0EEB+3jAnGQirKC/pR/VZpB6uKg2aPBkqIQP/7AOS1r6oIN0j1Nv0/Mf1NHMxcHT5JCwAeobYvB3nIKajPw4+ePqN0WBAXXBVhfAD9RJYraxGjN3tc8g7A9O4z2d2wzqMwX9XjUlCu3KROoS42xhs777cLWu3DfrN+gH2QUsuj3NSSx7WroWsZpTw2LinGWLO5i2XZ/cmRCNSiOe6gUtTbnIsJvI3trLaKITAloAbuwBua/EVCrgE6f93584cJsYrGEzYJT03iabgh03f0DCdtp8zGmzyzbEF4XxdJHOBw6PCnBbwTRMmHFxHySZdAYoKIRUtADnfTIJaUl5XoCkzR/zjBwAznkfING7haKCElE4XquMGuSgxsLcfe4dRyh1gDprQUOH9v9jjxcKoYujzYPI3vMz9D4nUvOyLxJ29Dhg83ZyBxzOWLvEjnmd9jQ6VOb4ZGPS36b9l7WkxQVNcg6HOdN1sMmx+aY8wx6xx3A9vA2I+xxZ2LX8lhdaUJXiDlehwOxG15mxgqGWK85TgSBEK+X2ZoSh01B5xgbGDib0WVW7IMQqz7HiCDw4fVKjK4ZwrYtZuN0BiZSN77M7joqdP0zx+1wfMLb4QXmRL3y1D4/w95T0bKPVpCv42W7lwdIeQUDs3byI2HNsb2uhNL27Iz8w3P48dff9F8u5lzaQ9Zv/injMzzmZ8IWBb4bQGJt8GtIWWLNp1wGMut5ufnJtYY66ntOqmpSLn2/sXhmFNF3m9LHZOP33cYymO3rwXqTXT7fuL5vr42n3O3zfl3Vah+eiH3ULMyB2fyEgKarEpmU5lidbhn4hTBukDNJE53uSUil08Ol/jFWY45r0rNvpf9Mev9WebjGz5Te/2r6r6npz4TxpySni6b0Y61A+X+eWnqq8W/6b00I3dwF578BWlN17g==

Steps to reproduce

build actions in userStore.js like actions: { setUser_id(user_id) { this.user_id = user_id; }, setNickname(nickname) { this.nickname = nickname; }, setEmail(email) { this.email = email; }, setAddress(address) { this.address = address; }, setLevel(level) { this.level = level; }, setAgreement(agreement) { this.agreement = agreement; }, setReg_date(reg_date) { this.reg_date = reg_date; }, async start(phone_number) {

        try {
            const response = await axios.post('user/', {
                phone_number: phone_number,
                user_id: this.user_id
            });
            console.log(response.data);

            this.user_id = response.data.user_id;
            this.nickname = response.data.nickname;
            this.email = response.data.email;
            this.address = response.data.address;
            this.level = response.data.level;
            this.agreement = response.data.agreement;
            this.reg_date = response.data.reg_date;

            router.push({ name: 'UserProfile', params: { user_id: this.user_id }});
        } catch (err) {
            console.log(err);
        }
    },
    async login(phone_number) {

        try{
            const response = await axios.post('login/', {
                phone_number: phone_number,
            });
            console.log(response.data);

            this.user_id = response.data.user_id;
            this.nickname = response.data.nickname;
            this.email = response.data.email;
            this.address = response.data.address;
            this.level = response.data.level;
            this.agreement = response.data.agreement;
            this.reg_date = response.data.reg_date;

            router.push({ name: 'MainPage'});

        }   catch (err) {
            console.log(err);
        }

    }
    
}, 

AND in export default,

setup() { const phone_number = ref(""); const userStore = useUserStore();

return { phone_number, userStore };

},

methods: { startUsingStore() { this.userStore.start(this.phone_number); },

startLogin() {
  this.userStore.login(this.phone_number);
},

}.

when click startLogin, not startUsingStore, this happens.

What is expected?

Login with only phone_number. (using Query)

What is actually happening?

cannot proceed because of need of parameter that caused by startUsingStore method which is not been clicked.

System Info

No response

Any additional comments?

No response

avatar
Aug 12th 2023
export const useUserStore = defineStore('user', {
  state: () => {
    return {
      userId: null,
    };
  },
});
const store = useStore();

store.userId = 'foo';
avatar
Aug 12th 2023

If you think Pinia has a bug, please provide feedback at https://github.com/vuejs/pinia. If it's a usage question, please ask in the GitHub discussions. Additionally, we need minimal reproduction.

avatar
Aug 14th 2023

It was not pinia bug. and resolved. Thanks.