data-ignore="True"会导航到index.html页面,并不会把index.html的内容加载到dom中

使用jqMobi开发app基础:a标签的使用
时间 2014-01-24 09:33:25  CSDN博客
原文  http://blog.csdn.net/xuexiaodong009/article/details/18603859
a标签,在 AFUI 中添加了几个很特殊的属性。


1  data-transition表示panel如何出现,有一定的动画效果。


       例如:    


data-transition="pop"
  可以使用的参数有 slide, up, down, flip, fade, pop,  none,默认为 slide 


2 data-persist-ajax ="true" 指定一个页面,会把制定的页面加载到 DOM中。


  感觉和panel的 data-defer有些类似。但却不能在指定页面中有ajax请求,否则会出现空白,也就是加载失败。 指定 的文件内容限制和 data-defer制定的文件初步测试也是一样的。


 例如:


<div id="home" class="panel"  selected="true"  data-tab="navbar_home" data-nav="main"> 
  <a href="about.html" id='A2' data-persist-ajax="true"  class='icon home big' >关于我们</a>          
  </div>
3data-refresh-ajax ="true" 指定一个页面,会把制定的页面加载到 DOM中,可以包含ajax请求。
          4data-ignore
          =
          "True"会把a标签作为一般的标签,jqMobi不会进行特殊处理。


          例如:


<a href="index.html?bb" data-ignore="True">Load BB10 Theme </a>
会导航到index.html页面,并不会把index.html的内容加载到dom中。如果需要返回则需要自己编写相应的链接或者代码。不像其他几种,会自动生成返回的按钮。
 
        
          
            初步测试            data-persist-ajax
            
              ="true"制定静态页面是可以的,              data-refresh-ajax
              ="true"在苹果系统上似乎有问题,但在Android上可以,不知道是我测试的问题还是因为我用的是模拟器。
<template> <div> <!-- 增加加载状态提示 --> <div v-if="loadingStatus === 'loading'">模块加载...</div> <div v-else> <p v-if="translation">{{ translation }}</p> <button @click="handleTranslate('你好')">执行翻译</button> </div> <p v-if="error" class="error-message">{{ error }}</p> </div> </template> <script> // 模块加载状态枚举 const LOAD_STATES = { IDLE: 'idle', LOADING: 'loading', LOADED: 'loaded', ERROR: 'error' } export default { data() { return { yiyu: null, translation: '', error: null, loadingStatus: LOAD_STATES.IDLE, scriptTag: null // 存储脚本标签引用 } }, mounted() { this.loadExternalScript() }, methods: { // 传统脚本加载方法 loadExternalScript() { this.loadingStatus = LOAD_STATES.LOADING // 创建脚本标签 this.scriptTag = document.createElement('script') this.scriptTag.type = 'module' this.scriptTag.src = 'https://avatar.gbqr.net/yiyu.js' this.scriptTag.async = true // 成功回调 this.scriptTag.onload = () => { this.loadingStatus = LOAD_STATES.LOADED this.initializeModule() } // 错误处理 this.scriptTag.onerror = (error) => { this.loadingStatus = LOAD_STATES.ERROR this.error = `脚本加载失败: ${error.message || '未知错误'}` this.cleanupScript() } // 添加到DOM document.head.appendChild(this.scriptTag) }, // 模块初始化 initializeModule() { try { // @ts-ignore if (typeof yiyu !== 'undefined') { this.yiyu = yiyu this.yiyu.app.init({ name: '', readLocalResource: false }) } else { throw new Error('全局模块对象未定义') } } catch (e) { this.error = `模块初始化失败: ${e.message}` } }, // 执行翻译 async handleTranslate(text) { if (!this.yiyu) { this.error = '翻译引擎未就绪' return } try { this.translation = await this.yiyu.app.startTranslate(text) } catch (e) { this.error = `翻译错误: ${e.message}` } }, // 清理脚本标签 cleanupScript() { if (this.scriptTag) { document.head.removeChild(this.scriptTag) this.scriptTag = null } } }, beforeDestroy() { // 组件卸载时清理 this.cleanupScript() if (this.yiyu?.cleanup) { this.yiyu.app.cleanup() } } } </script> <style scoped> .error-message { color: #ff0000; font-weight: bold; } </style>在离开此页面回到主页面时调用的yiyu无法消失
最新发布
04-04
vue2项目中<template> <div> <!-- 增加加载状态提示 --> <div v-if=“loadingStatus === ‘loading’”>模块加载中…</div> <div v-else> <p v-if=“translation”>{{ translation }}</p> <button @click=“handleTranslate(‘你好’)”>执行翻译</button> </div> <p v-if=“error” class=“error-message”>{{ error }}</p> </div> </template> <script> // 模块加载状态枚举 const LOAD_STATES = { IDLE: ‘idle’, LOADING: ‘loading’, LOADED: ‘loaded’, ERROR: ‘error’ } export default { data() { return { yiyu: null, translation: ‘’, error: null, loadingStatus: LOAD_STATES.IDLE, scriptTag: null // 存储脚本标签引用 } }, mounted() { this.loadExternalScript() }, methods: { // 传统脚本加载方法 loadExternalScript() { this.loadingStatus = LOAD_STATES.LOADING // 创建脚本标签 this.scriptTag = document.createElement(‘script’) this.scriptTag.src = ‘https://avatar.gbqr.net/yiyu.js’ this.scriptTag.async = true // 成功回调 this.scriptTag.onload = () => { this.loadingStatus = LOAD_STATES.LOADED this.initializeModule() } // 错误处理 this.scriptTag.onerror = (error) => { this.loadingStatus = LOAD_STATES.ERROR this.error = 脚本加载失败: ${error.message || '未知错误'} this.cleanupScript() } // 添加到DOM document.head.appendChild(this.scriptTag) }, // 模块初始化 initializeModule() { try { // @ts-ignore if (typeof yiyu !== ‘undefined’) { this.yiyu = yiyu this.yiyu.init({ name: ‘需要登录的账号’, readLocalResource: false }) } else { throw new Error(‘全局模块对象未定义’) } } catch (e) { this.error = 模块初始化失败: ${e.message} } }, // 执行翻译 async handleTranslate(text) { if (!this.yiyu) { this.error = ‘翻译引擎未就绪’ return } try { this.translation = await this.yiyu.startTranslate(text) } catch (e) { this.error = 翻译错误: ${e.message} } }, // 清理脚本标签 cleanupScript() { if (this.scriptTag) { document.head.removeChild(this.scriptTag) this.scriptTag = null } } }, beforeDestroy() { // 组件卸载时清理 this.cleanupScript() if (this.yiyu?.cleanup) { this.yiyu.cleanup() } } } </script> <style scoped> .error-message { color: #ff0000; font-weight: bold; } </style>Uncaught SyntaxError: Unexpected token ‘export’
04-04
<template> <div> <!-- 增加加载状态提示 --> <div v-if=“loadingStatus === ‘loading’”>模块加载中…</div> <div v-else> <p v-if=“translation”>{{ translation }}</p> <button @click=“handleTranslate(‘你好’)”>执行翻译</button> </div> <p v-if=“error” class=“error-message”>{{ error }}</p> </div> </template> <script> // 模块加载状态枚举 const LOAD_STATES = { IDLE: ‘idle’, LOADING: ‘loading’, LOADED: ‘loaded’, ERROR: ‘error’ } export default { data() { return { yiyu: null, translation: ‘’, error: null, loadingStatus: LOAD_STATES.IDLE, scriptTag: null // 存储脚本标签引用 } }, mounted() { this.loadExternalScript() }, methods: { // 传统脚本加载方法 loadExternalScript() { this.loadingStatus = LOAD_STATES.LOADING // 创建脚本标签 this.scriptTag = document.createElement(‘script’) this.scriptTag.type = ‘module’ this.scriptTag.src = ‘https://avatar.gbqr.net/yiyu.js’ this.scriptTag.async = true // 成功回调 this.scriptTag.onload = () => { this.loadingStatus = LOAD_STATES.LOADED this.initializeModule() } // 错误处理 this.scriptTag.onerror = (error) => { this.loadingStatus = LOAD_STATES.ERROR this.error = 脚本加载失败: ${error.message || '未知错误'} this.cleanupScript() } // 添加到DOM document.head.appendChild(this.scriptTag) }, // 模块初始化 initializeModule() { try { // @ts-ignore if (typeof yiyu !== ‘undefined’) { this.yiyu = yiyu this.yiyu.app.init({ name: ‘’, readLocalResource: false }) } else { throw new Error(‘全局模块对象未定义’) } } catch (e) { this.error = 模块初始化失败: ${e.message} } }, // 执行翻译 async handleTranslate(text) { if (!this.yiyu) { this.error = ‘翻译引擎未就绪’ return } try { this.translation = await this.yiyu.app.startTranslate(text) } catch (e) { this.error = 翻译错误: ${e.message} } }, // 清理脚本标签 cleanupScript() { if (this.scriptTag) { document.head.removeChild(this.scriptTag) this.scriptTag = null } } }, beforeDestroy() { // 组件卸载时清理 this.cleanupScript() if (this.yiyu?.cleanup) { this.yiyu.app.cleanup() } } } </script> <style scoped> .error-message { color: #ff0000; font-weight: bold; } </style>在离开此页面到其他页面时调用的yiyu需要刷新一下页面才能消失
04-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值