Skip to content

use mobx Failed to compile err #2367

Closed
Closed
@zanjs

Description

@zanjs
Failed to compile
./src/stores/Store.js
Syntax error: E:/2017/react/antd/src/stores/Store.js: Unexpected token (8:2)

   6 | 
   7 | export default class Store {
>  8 |   @observable counter = 10;
     |   ^
   9 | 
  10 |   @observable users = [];
  11 | 

Store.js

import { observable, when, action } from "mobx";
import axios from "axios";
import { fromPromise } from "mobx-utils";

const apiRoot = "https://jsonplaceholder.typicode.com";

export default class Store {
  @observable counter = 10;

  @observable users = [];

  @action increaseCounter() {
    this.counter += 1;
  }
  @action decreaseCounter() {
    this.counter -= 1;
  }
  @action fetch() {
    let fetchResult = fromPromise(axios.get(`${apiRoot}/users`));

    // combine with when..
    when(() => fetchResult.state !== "pending", () => {
      console.log("Got it!");
      this.users = fetchResult.value.data;
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions