我在我的 vue 專案中使用 phonegap-nfc 庫。它可以作業,但我不知道為什么它會在其他頁面資訊中打開我在 NFC 汽車上的資訊。我想要做的是顯示 NFC 在我的應用程式中的所有資訊。所以,如果有人知道該怎么做,你能幫我嗎?
這是我的代碼:
<template>
<v-app>
<v-card-actions>
<div class="cardInfos">
{{ tagId }}
{{ message }}
</div>
</v-card-actions>
</v-app>
</template>
<script>
export default {
name: 'App',
data: () => ({
tagId: "",
message: ""
}),
methods:{
scanNFC(){
window.nfc.enabled(
() => {
// NFC enabled
this.registerTagEvent()
},
(error) => {
if (error === 'NFC_DISABLED') {
// Trigger the phone settings to enable the NFC settings
window.nfc.showSettings()
} else if (error === 'NO_NFC') {
navigator.notification.alert('Cannot scan NFC', () => {}, 'No NFC', 'OK')
}
}
)
},
registerTagEvent () {
window.nfc.addTagDiscoveredListener(
this.displayNdef,
() => {
console.log('succeess registering ndef listener')
},
(error) => {
console.log('failure registering ndef listener', error)
}
)
},
displayNdef (nfcEvent) {
// Decode tag data from the plugin
const bgColor = document.getElementsByClassName(".v-application--wrap")
bgColor.style.backgroudColor = "green"
let tag = nfcEvent.tag
let tagId = window.nfc.bytesToHexString(tag.id)
let message = window.nfc.bytesToString(tag.ndefMessage[0].payload)
this.tagId = tagId
this.message = message
window.ndefMessage(tagId, message)
}
},
deactivated () {
this.unregisterTagEvent()
},
unregisterTagEvent () {
// Test if the plugin is defined
if ((typeof nfc) !== 'undefined') {
window.nfc.removeNdefListener(this.displayNdef)
}
},
};
</script>
誰能幫幫我:)
uj5u.com熱心網友回復:
我通過以下步驟解決了問題:
在股票 Android 上禁用標簽應用程式的步驟:
導航到設定 單擊應用程式和通知 單擊查看所有應用程式(通常在最近打開的應用程式下) 單擊右上角的 3 個點 單擊顯示系統(這將啟用所有系統安裝的應用程式) 搜索應用程式(默認 nfc 應用程式,您將在讀取 NFC 標簽時的選擇選項中看到該應用程式通常稱為標簽:單擊應用程式串列中的標簽應用程式單擊禁用,然后在禁用應用程式周圍顯示的任何對話框上單擊確定
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/471412.html
標籤:javascript Vue.js 科尔多瓦 NFC
