我定义了自己的模块并在nuxt.config.js中注册。如何在模块中使用钩子?
我试图这样做,因为文档说https://nuxtjs.org/guide/modules(参见页面底部),但钩子似乎没有被触发。
module.exports = function () {
console.log('hello from modules');
this.nuxt.hook('module', moduleContainer => {
console.log('modules!!!');
});
this.nuxt.hook('renderer', (renderer) => {
console.log('renderer created');
renderer.hook('render:done', (render) => {
console.log('renderer done');
});
});
};
模块正在加载('hello from modules')但没有一个钩子正在开始。
任何帮助都将不胜感激。
答案 0 :(得分:1)
这些是相应的文档:
基于这些,nuxt钩可以用作:
// Import statements
import { fetchMovies, fetchGenres } from '/path/to/actionCreators';
// Your react component somewhere here.
const mapStateToProps = state => {
// This is the longhand of what you did
return {
genres: state.genres,
movies: state.movies.items,
newMovie: state.movies.item,
editedMovie: state.movies.item
};
};
/**
* It's generally more clear to have mapDispatchToProps
* as a variable instead of passing the object directly
* to the connect. It's not wrong though. Make sure these
* are imported.
*/
const mapDispatchToProps = {
fetchMovies
fetchGenres
};
export default connect(mapStateToProps, mapDispatchToProps)