我可以使用Axios从VueJs中的本地json获取一些信息。如果是,如何?

问题描述 投票:-1回答:1

问题:我正在尝试通过比较输入的订单ID来获取信息在VUEJS中搜索输入。每当我搜索任何订单ID时,都应该请求GET Ang使用Axios进入我的本地JSON。当订单ID在输入中输入的与我本地JSON中的订单ID相等应该显示属于订单ID的其他信息。否则它将显示我的404错误页面。我尝试了很多次但是每次我失败有人可以帮我吗?


一些伪造的JSON数据。这是要获取的JSON数据。


api_received_data = { "order_number": "ssyhhsdlks", "first_name": "Islombek", "last_name": "Mamatqulov", "phone_number": +998999999999, "address":{
    "address_1": "123 Beruniy ko'chasi"
    "address_2": "Shayxontohur",
    "address_3"  "",
    "city": "Tashkent"
    "postcode": "1003939" }, "status": "Shipped to London", "cart_id": 23, "products":   {[{"order": 1,
     "title": "iphone XS max",
     "status": "delivered"},
     {"order": 2,
     "title": "macbook pro",
     "status": "arrived in tashkent"},
     {"order":3,
     "title": "iPad",
     "status": "shipped to london"}]} } 

结果必须是:通过在搜索中输入订单ID来获取类似表格的信息按下执行按钮时输入。尝试给用户

vue.js get compare axios id
1个回答
0
投票
(直接来自axios文档的代码)

const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} });

baseurl是您的json文件所在目录的绝对URL。然后,您可以使用axios get请求它们。

instance.get('someFile.json')

这样做的一个不错的功能是,如果您需要使用带有不同URL的axios get,则仅当不使用绝对路径时才使用基本URL。因此,如果以后使用axios.get('http://some-domain.com/some-end-point/),则baseURL将自动被忽略。

© www.soinside.com 2019 - 2024. All rights reserved.