博客
关于我
nuxt全栈仿美团官网10——目录
阅读量:112 次
发布时间:2019-02-26

本文共 1140 字,大约阅读时间需要 3 分钟。

建立目录数据模型并完成数据库导入

在完成教材数据的导入后,我们需要设计数据模型结构,并将数据导入数据库。以下是具体的操作步骤:

  • 在server目录下创建dbs_copy目录,将教材中的数据库文件*.dat全部复制进去。

  • 配置MongoDB环境变量。在系统变量的path中添加MongoDB安装的bin目录,然后在dbs_copy目录下打开命令行窗口(如Git Bash),执行以下命令将menus集合导入student数据库:

    mongoimport -d student -c menus menus.dat

    使用相同的方法导入其他数据文件。

  • 接下来,我们需要在数据库中创建对应的数据模型。以下是使用Mongoose的示例代码:

    import mongoose from 'mongoose';const menuSchema = mongoose.Schema({  menu: {    type: Array,    required: true  }});export default mongoose.model('menu', menuSchema);

    完成数据库模型设计后,下一步是开发获取目录数据的接口。建议在geo.js中增加相应的RESTful API,并进行测试以确保数据能够正确查询和返回。

    为了方便管理目录数据,我们建议在store中创建对应的状态管理。以下是一个典型的 Vuex store 实现示例:

    const state = {  menu: []};const mutations = {  setMenu(state, menu) {    state.menu = menu;  }};const actions = {  setMenu({ commit }, menu) {    commit('setMenu', menu);  }};export default {  namespaced: true,  state,  mutations,  actions};

    最后,我们需要在Nuxt项目的nuxtServerInit方法中进行store的初始化。例如,在store.js中添加以下代码:

    import { mapGetters } from 'vuex';export default {  namespaced: true,  state: {    home: {      menu: []    }  },  mutations,  actions};

    在组件中使用store数据时,可以采用以下方式:

    通过以上步骤,我们可以完成目录数据的整体管理和展示。

    转载地址:http://azoy.baihongyu.com/

    你可能感兴趣的文章
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    nnU-Net 终极指南
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named 'pandads'
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>