Skip to content

Commit

Permalink
Add a global function to get country tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuan9522 committed Sep 16, 2022
1 parent 6f37c0b commit 2d28eb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import countries from './assets/json/country.json'

const getCountryTag = (countryCode, type = 'movie') => {
if(!countryCode) return null
const code = countryCode.toLowerCase()

switch(type) {
case 'tv':
return countries[code].drama_cn || countries[code].chinese;
case 'movie':
default:
return countries[code].chinese
}
}

export { getCountryTag }
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { tmdb, omdb } from './axios'
import { getCountryTag } from './common'
import './assets/css/index.css'
import '@vant/touch-emulator' // 沒有這個,vant 有些 click 不會被觸發,例如: Search 裡的 clear
import {
Expand Down Expand Up @@ -30,6 +31,7 @@ const global = {
: Math.sign(num) * Math.abs(num)
},
$omdb: omdb,
$getCountryTag: getCountryTag
}

app.provide('$global', global)
Expand Down

0 comments on commit 2d28eb7

Please sign in to comment.