Previously I used the standard < script > tag with the setup function within it:
<script>
import { ref } from 'vue'
import useLogin from '../composables/useLogin'
const email = ref('')
const password = ref('')
export default {
setup(props, context){
const {error, login} = useLogin()
const handleLoginSubmit = async () => {
await login(email.value, password.value)
if(!error.value){
context.emit('login')
}
router.push({name: 'home'})
}
return { email, password, handleLoginSubmit }
}
}
</script>
Now I tried to switch to the < script setup > tag, but I don't know how to access the context attribute here.
<script setup>
import { ref } from 'vue'
import useLogin from '../composables/useLogin'
import router from '../router'
const email = ref('')
const password = ref('')
const {error, login} = useLogin()
const handleLoginSubmit = async () => {
await login(email.value, password.value)
if(!error.value){
context.emit('login')
}
router.push({name: 'home'})
}
</script>
I get the following error due to the missing definition of the context.
Uncaught ReferenceError: context is not defined
I tried to import context from vue in different ways, but nothing seems to be the correct.