小编hoo*_*vhd的帖子

如何在 Nuxt 的 asyncData 中重定向

我是 vue.js 的新手,我有一个简单的问题。

我有如下代码:

  asyncData({ params, error }) {
    return Job.api()
      .fetchByID(params.id)
      .then((response) => {
        const selectedJob = response.entities.jobs[0]
        if (selectedJob) {
          const industryID = selectedJob.industryId
          return Industry.api()
            .fetchByID(industryID)
            .then((result) => {
              const jobInd = result.response.data
              return {
                tagsArray:
                  selectedJob.tags === 'null' || selectedJob.tags === ''
                    ? []
                    : selectedJob.tags.split(','),
                job: selectedJob,
                jobIndustry: jobInd,
              }
            })
            .catch(() => {
              error({
                statusCode: 404,
                message: 'Job Industry not found',
              })
            })
        }
      })
      .catch(() => {
        error({
          statusCode: 404,
          message: 'Job not …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-router vue-component vuejs2 nuxt.js

3
推荐指数
1
解决办法
5420
查看次数

标签 统计

nuxt.js ×1

vue-component ×1

vue-router ×1

vue.js ×1

vuejs2 ×1