调用Action vuex且内部没有任何突变是否不好?

时间:2019-10-29 11:47:55

标签: vue.js vuex

我正在尝试移动与Vuex相关的API的所有内容,但是在某些情况下,我实际上不需要在调用操作后进行任何更改,可以吗?最佳做法是什么?

actions: {
  save (context, payload) {
    axios.post(`http://jsonplaceholder.typicode.com/posts`, {body: payload})
  }
}

1 个答案:

答案 0 :(得分:2)

如果您只需要将信息发布到API且不更改状态,那么我会说这几乎可以!

但是,如果您不更改任何状态,那么应用程序如何更改其内容以使用户知道API发布有效还是失败?

最佳做法是根据axios承诺@app.route( '/cars/<int:car_shop_id>/menu/new/', methods=['GET', 'POST']) def newCar(car_shop_id): if 'username' not in login_session: return redirect('/login') session = connect_to_database() if request.method == 'POST': newItem = Cars(name=request.form['name'], description=request.form['description'], price=request.form['price'], car_shop_id=car_shop_id) session.add(newItem) session.commit() flash("Car has been added") return redirect(url_for('Car_shopMenu', car_shop_id=car_shop_id)) else: return render_template('newcars.html', car_shop_id=car_shop_id) { "id" : "1234", "name" : "David", "request" : { "url" : "www.stackoverflow.com", "method" : "POST", "bodyPatterns" : [ { "matchesXPath" : "example" }, { "matchesXPath" : "example/123" }, { "matchesXPath" : { "expression" : "example/123/123/text()", "equalTo" : "bbbb" } } ] } }

改变状态
resolve