Vue.js通过路由href链接传递参数

时间:2020-06-30 14:31:22

标签: javascript vue.js vuetify.js

我刚接触Vuejs,所以对不起!
我有一个名为“ Goods”的组件,它显示了路径路径中的所有项目(“ / Goods”),还有一个名为“ AddGoods”的组件,位于(“ / AddGoods”),它是一种表单并将数据提交到我的数据库表中。 我必须为这两个使用两个单独的页面,并且它们之间紧密协作。 现在,我还希望能够使用AddGoods表单来编辑和显示我已添加的商品的详细信息,而且我很难找到一种通过链接发送某些参数的方法,以便我可以基于每个字段管理字段和按钮情况(例如将字段设置为只读以显示详细信息等)。

这是我的route.js:

class ClassicLevelScene: SKScene { 
// Right Pointing Cannons
var rightPointingCannon: [SKReferenceNode] = []

// Dodgeball 5 Constants
var dodgeball5 = SKSpriteNode(imageNamed: "dodgeball5")

// Dodgeball SKActions
var dodgeballRepeat = SKAction()
let dodgeballMoveLeft = SKAction.moveBy(x: -400, y: 0, duration: 0.5)
let dodgeballMoveRight = SKAction.moveBy(x: 400, y: 0, duration: 0.5)
let dodgeballMoveDone = SKAction.removeFromParent()
let dodgeballWait = SKAction.wait(forDuration: 1)
var dodgeballLeftSequence = SKAction()
var dodgeballRightSequence = SKAction()


override func didMove(to view: SKView) {

    // Cannon Setup
    for child in self.children {
      if child.name == "rightPointingCannon" {
        if let child = child as? SKReferenceNode {
            rightPointingCannon.append(child)
            dodgeball5.position = child.position
            run(SKAction.repeatForever(
              SKAction.sequence([
                SKAction.run(spawnDodgeball),
                SKAction.wait(forDuration: 1.0)
                ])
            ))

        }
      }
    }
    
    // Dodgeball Right Sequence
    dodgeballRightSequence = SKAction.sequence([dodgeballMoveRight, dodgeballMoveDone, dodgeballWait])


}

func spawnDodgeball() {
    dodgeball5.zPosition = -1
    dodgeball5.size = CGSize(width: 30, height: 30)
    addChild(dodgeball5)
    dodgeball5.run(dodgeballRightSequence)
}
}

,这是“ AddGoods”的链接:

{
    path: "/addGoods",
    name: "add goods",
    meta: {
      title: "Add Goods",
    },
    component: () => import("../views/GoodsManagment/AddGoods.vue"),
  },
  {
    path: "/goodsTbl",
    name: "goods tbl",

    meta: {
      title: "Goods Table",
    },
    component: () => import("../views/GoodsManagment/GoodsTbl.vue"),
  },

1 个答案:

答案 0 :(得分:0)

所以我最终这样做了:

route.js:

{
    path: "/addGoods/:id",
    name: "add goods",
    meta: {
      title: "Add Goods",
    },
    component: () => import("../views/GoodsManagment/AddGoods.vue"),
  },
  {
    path: "/goodsTbl",
    name: "goods tbl",

    meta: {
      title: "Goods Table",
    },
    component: () => import("../views/GoodsManagment/GoodsTbl.vue"),
  },

并称之为,我个人发现Programmatic Navigation更易于使用,所以:

this.$router.push({name: "add goods", params: { id: 123 }});