【发布时间】:2021-09-17 05:28:18
【问题描述】:
当我运行这个源代码时,它只显示给我
[Kakao 未定义] https://i.stack.imgur.com/UA7VI.png
我的来源是这样的
在『nuxt.config.js』中
export default {
// Global page headers (https://go.nuxtjs.dev/config-head)
head: {
script: [
{ src: 'https://developers.kakao.com/sdk/js/kakao.js'},
]
},
}
在『./pages/login.vue』
<template>
<a :href="loginWithKakao()">
<img
src="https://k.kakaocdn.net/14/dn/btqCn0WEmI3/nijroPfbpCa4at5EIsjyf0/o.jpg"
width="222"
/>
</a>
</template>
<script>
export default {
data() {
return {
visible: true,
account: '',
password: '',
}
},
computed: {
...mapState('store', { logo: (state) => state.logo }),
},
methods: {
loginWithKakao() {
Kakao.Auth.login({
success: function (response) {
// console.log("Kakao.Auth.login - success response ->", response);
Kakao.API.request({
url: '/v2/user/me',
success: function (response) {
console.log(response)
},
fail: function (error) {
console.log(error)
},
})
},
fail: function (error) {
console.log(error)
},
})
},
},
mounted(){
// Initialize the SDK. Please set the JavaScript key for the app you want to use.
Kakao.init('JavaScript key');
// Determines whether to initialize the SDK.
console.log('Kakao.isInitialized() >>', Kakao.isInitialized());
},
}
</script>
当我在 html 中使用它时,它起作用了
<a id="custom-login-btn" href="javascript:loginWithKakao()">
<img
src="https://k.kakaocdn.net/14/dn/btqCn0WEmI3/nijroPfbpCa4at5EIsjyf0/o.jpg"
width="222"
/>
</a>
据我所知,我们可以将 html 中的 href="javascript:your_function()" 用作 Vue.js 中的 :href="your_function()"
或者有其他方法吗?
【问题讨论】:
-
您的文件中有 import
Kakao。import Kakao from 'Kakao'像这样。 -
我在 nuxt.config.js 中添加了“kakao 脚本 js 文件”。无论如何,我试图在
-
从这里安装 npmjs.com/package/kakao 。并添加点击事件而不是 href。
标签: javascript html vue.js