问题描述
我正在使用 React 应用程序并尝试使用来自 movieTrailer(..)
的 movie-trailer
。
问题是一直说 movieTrailer(movie.name || "")
从未定义过。我确实导入了 import movieTrailer from 'movie-trailer';
并且在“/Users/kevinsong/Desktop/netflix-clone/node_modules/movie-trailer/index.js”中有一个名为 movieTrailer
async function movieTrailer( movie,options,cb,legacy ) {
/* Fetch movie trailers */
// Massage inputs
let config = {
multi: false,id: false,year: null,language: null,// Public Key on purpose
apiKey: '9d2bff12ed955c7f1f74b83187f188ae'
}
if ( !options ) {
options = {}
}
if ( typeof movie !== 'string' && !options.tmdbId ) {
throw Error( 'Expected first parameter to be a movie or TMDB ID (string)' )
} else if ( typeof options === 'function' ) {
// Second parameter is the callback
cb = options
options = null
} else if ( typeof options === 'boolean' || options === 'true' ) {
// Second parameter is multi
config.multi = options
} else if ( typeof options === 'string' || typeof options === 'number' ) {
// Second parameter is year
config.year = options
/* BACKWARDS-COMPATABILITY FOR v1 */
if ( typeof legacy === 'function' && ( typeof cb === 'boolean' || ( typeof cb === 'string' && cb === 'true' ) ) ) {
// Third parameter is multi
config.multi = cb
cb = legacy
}
/* END BACKWARDS-COMPATABILITY */
} else if ( typeof options === 'object' ) {
// Set options
config = Object.assign( config,options )
}
// Remove invalid callback
if ( typeof cb !== 'function' ) {
cb = null
}
const movieId = config.tmdbId ? config.tmdbId : ( await getMovieId( movie,config )
.catch( error => {
handleErrors(error)
return null
} ) )
// Get the TMDB content ID
if ( !movieId ) {
// Failed
return null
}
// Get the trailers themselves
const result = getTrailer( movieId,config )
if ( !result ) {
// Failed
return null
}
// Call callback if supplied
if ( cb ) {
return result
.then( response => cb( null,response ) )
.catch( error => cb( error,null ) )
}
// return promise
return result
}
// Exposed public method
return movieTrailer
}
请帮助我解释为什么我收到未定义的 movieTrailer
引用错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)