cmp-cc / vue-cookies

A simple Vue.js plugin for handling browser cookies
MIT License
408 stars 70 forks source link

support vue3? #84

Closed fengluo2 closed 1 year ago

fengluo2 commented 1 year ago

Are you sure to support vue3? The sample example does not work.

cmp-cc commented 1 year ago

I need more information

fengluo2 commented 1 year ago

https://github.com/cmp-cc/vue-cookies/blob/master/sample/welcome-v3.html This,He can't work properly

cmp-cc commented 1 year ago

This is a simple example that can be opened directly from the browser without the http server

Is there an error message in f12? You can copy it

fengluo2 commented 1 year ago

oh.This is my problem. I moved the file to another place, causing it to fail to load cookies. js

fengluo2 commented 1 year ago

wait,He still can't seem to work. main.ts

......
const app = createApp(App)

app.use(router)
    .use(pinia)
    .use(VueCookies)
    .use(ElementPlus)
    .mount('#app')
......

test.vue

......
<el-button @click="test">test</el-button>
......
<script lang="ts" setup>

const test = () => {
  this.$cookies.set("a","b")
}
</script>
......

browser console output error

Uncaught TypeError: Cannot read properties of undefined (reading '$cookies')
    at test (test.vue:8:8)
    at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:164:21)
    at emit$1 (runtime-core.esm-bundler.js:718:9)
    at runtime-core.esm-bundler.js:7388:53
    at handleClick (use-button.ts:46:5)
    at createElementBlock.onClick._cache.<computed>._cache.<computed> (button.vue:73:2)
    at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
    at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:164:21)
    at HTMLButtonElement.invoker (runtime-dom.esm-bundler.js:339:9)
cmp-cc commented 1 year ago

This is not in the lifecycle of Vue. You can study Vue Options API or Composition API,use it.

fengluo2 commented 1 year ago

thank you. I've run it successfully. This gave me a better understanding of vue.