PROUMB_ios安卓 testlight proumb.cow/apps/android开发包安装ggzy.jianxi

本文介绍了如何使用`require.context`在Vue中批量导入组件,以减少重复代码,并讲解了`watch`对象的常用用法,包括立即执行、深度监听等功能,帮助优化组件管理和响应式更新。

PROUMB_ios安卓 testlight proumb.cow/apps/android开发包安装ggzy.jianxi

require.context()
场景:如页面需要导入多个组件,原始写法:
import titleCom from '@/components/home/titleCom'
import bannerCom from '@/components/home/bannerCom'
import cellCom from '@/components/home/cellCom'
components:{titleCom,bannerCom,cellCom}
复制代码
这样就写了大量重复的代码,利用 require.context 可以写成
const path = require('path')
const files = require.context('@/components/home', false, /\.vue$/)
const modules = {}
files.keys().forEach(key => {
  const name = path.basename(key, '.vue')
  modules[name] = files(key).default || files(key)
})
components:modules
复制代码
这样不管页面引入多少组件,都可以使用这个方法
3.API 方法
实际上是 webpack 的方法,vue 工程一般基于 webpack,所以可以使用
require.context(directory,useSubdirectories,regExp)
接收三个参数:
directory:说明需要检索的目录
useSubdirectories:是否检索子目录
regExp: 匹配文件的正则表达式,一般是文件名
复制代码
2.watch
2.1 常用用法
1.场景:表格初始进来需要调查询接口 getList(),然后input 改变会重新查询
created(){
  this.getList()
},
watch: {
  inpVal(){
    this.getList()
  }
}
复制代码
2.2 立即执行
2.可以直接利用 watch 的immediate和handler属性简写
watch: {
  inpVal:{
    handler: 'getList',
      immediate: true
  }
}
复制代码
2.3 深度监听
3.watch 的 deep 属性,深度监听,也就是监听复杂数据类型
watch:{
  inpValObj:{
    handler(newVal,oldVal){
      console.log(newVal)
      console.log(oldVal)
    },
    deep:true
  }
}

import requests from pprint import pprint import csv from bs4 import BeautifulSoup import time import re # 打开CSV文件 f = open('data.csv', mode='w', encoding='utf-8-sig', newline='') # utf-8-sig解决Excel乱码问题 csv_writer = csv.DictWriter(f, fieldnames=[ '公告标题', '公告类型', '发布平台', '来源', '公告性质', '公告编号', '发布时间', '公告内容' # 新增字段 ]) csv_writer.writeheader() headers = { 'Cookie': "_horizon_uid=001e9df8-858d-4f41-9941-f9e5fb1921bb; _horizon_sid=2853a973-409a-4dbf-99c2-8764a93daa9f", "Referer": "https://ygp.gdzwfw.gov.cn/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" } # 公告详情页基础URL DETAIL_BASE_URL = "https://ygp.gdzwfw.gov.cn/ggzy-portal/v1/notice/detail" link = 'https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items' data = { "type": "trading-type", "openConvert": False, "keyword": "", "siteCode": "44", "secondType": "D", "tradingProcess": "", "thirdType": "[]", "projectType": "", "publishStartTime": "", "publishEndTime": "", "pageNo": 1, "pageSize": 10 } # 获取公告列表数据 link_data = requests.post(url=link, json=data, headers=headers).json() pagedatas = link_data['data']['pageData'] # 遍历每个公告 for index in pagedatas: # 构建公告详情页请求参数 detail_params = { 'noticeId': index['noticeId'], 'projectCode': index['projectCode'], 'bizCode': index['bizCode'], 'siteCode': index['siteCode'], 'publishDate': index['publishDate'] } # 获取公告详情内容 try: # 添加延迟避免请求过快 time.sleep(1) # 获取公告详情 detail_response = requests.get( DETAIL_BASE_URL, params=detail_params, headers=headers ) detail_data = detail_response.json() # 提取公告内容 - 根据实际响应结构调整 notice_content = detail_data.get('data', {}).get('mb-10', '') # 使用BeautifulSoup清理HTML标签 if notice_content: soup = BeautifulSoup(notice_content, 'html.parser') # 保留换行格式 for br in soup.find_all('br'): br.replace_with('\n') notice_content = soup.get_text(separator='\n', strip=True) except Exception as e: print(f"获取公告内容失败: {e}") notice_content = "内容获取失败" # 构建数据字典 dit = { '公告标题': index['noticeTitle'], '公告类型': index['noticeTypeDesc'], '发布平台': index['pubServicePlat'], '来源': index['pubServicePlat'], '公告性质': index['noticeNature'], '公告编号': index['noticeId'], '发布时间':index['publishDate'], '公告内容': notice_content # 新增公告内容 } pprint(dit) csv_writer.writerow(dit) f.close() print("数据抓取完成,已保存到data.csv") 为何运行完上面代码后只有内容公告显示内容获取失败
最新发布
12-06
import requests from pprint import pprint import csv from bs4 import BeautifulSoup #模拟浏览器 f=open('data.csv',mode='w',encoding='utf-8',newline='') csv_writer = csv.DictWriter(f,fieldnames=[ '公告标题', '公告类型', '发布平台', '来源', '公告性质', '公告编号', ]) csv_writer.writeheader() headers = { 'Cookie':"_horizon_uid=001e9df8-858d-4f41-9941-f9e5fb1921bb; _horizon_sid=2853a973-409a-4dbf-99c2-8764a93daa9f", "Referer":"https://ygp.gdzwfw.gov.cn/", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36" } #url="https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items" link='https://ygp.gdzwfw.gov.cn/ggzy-portal/search/v2/items' data={"type":"trading-type","openConvert":False,"keyword":"","siteCode":"44", "secondType":"D","tradingProcess":"","thirdType":"[]","projectType":"","publishStartTime":"","publishEndTime":"","pageNo":1,"pageSize":10} link_data = requests.post(url=link,json=data,headers=headers).json() pprint(link_data) pagedatas = link_data['data']['pageData'] for index in pagedatas: url=f"'https://ygp.gdzwfw.gov.cn/#/44/new/jygg/v3/D?noticeId='+index['noticeId']+'&projectCode='+index['projectCode']+'&bizCode='+index['bizCode']+'&siteCode='+index['siteCode']+'&publishDate='+index['publishDate']" # ——新增结束—— dit={ '公告标题':index['noticeTitle'], '公告类型':index['noticeTypeDesc'], '发布平台':index['pubServicePlat'], '来源':index['pubServicePlat'], '公告性质':index['noticeNature'], '公告编号':index['noticeId'] } pprint(dit) csv_writer.writerow(dit)
12-05
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值